如何解决从 C# 作为进程运行 ngrok 控制台应用程序不起作用
亲爱的 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();
}
解决方法
您使用“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();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。