【问题标题】:Running ngrok console application as a process from C# does not work从 C# 将 ngrok 控制台应用程序作为进程运行不起作用
【发布时间】:2021-08-14 21:02:33
【问题描述】:

尊敬的 Stack Overflow 社区,

我正在尝试使用 C# 与 Ngrok 控制台进行通信。不幸的是,“StartInfo.Arguments”不起作用。比如我在c#代码中写"StartInfo.Arguments=" ngrok",不会出现ngrok帮助文本,但是日志中会出现"ERROR: Unrecognized command: ngrok"。但是如果我自己打开控制台,写上“ngrok”就可以了。

private void startServer()

        Process compiler = new Process();
        compiler.StartInfo.FileName = "ngrok.exe";
        compiler.StartInfo.Arguments = "\"ngrok\"";
        compiler.StartInfo.UseShellExecute = false;
        compiler.StartInfo.RedirectStandardOutput = true;
        compiler.Start();

        Console.WriteLine(compiler.StandardOutput.ReadToEnd());

        compiler.WaitForExit();
    }

【问题讨论】:

    标签: c# .net process console ngrok


    【解决方案1】:

    您使用“ngrok”作为参数。这与您在控制台中写入ngrok.exe ngrok 相同。 ngrok 无法识别该命令。尝试使用正确的参数,例如 compiler.StartInfo.Arguments = "http 80"; 或将其留空。如果您想通过 http 使用端口 80 的 ngrok,您的代码必须如下所示:

    private void startServer()
    
        Process compiler = new Process();
        compiler.StartInfo.FileName = "ngrok.exe";
        compiler.StartInfo.Arguments = "http 80";
        compiler.StartInfo.UseShellExecute = false;
        compiler.StartInfo.RedirectStandardOutput = true;
        compiler.Start();
    
        Console.WriteLine(compiler.StandardOutput.ReadToEnd());
    
        compiler.WaitForExit();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-04
      • 1970-01-01
      • 2022-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-14
      相关资源
      最近更新 更多