c# - 从 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();
}
推荐阅读
- r - raster::overlay 带有调用向量列表的函数
- python - 蟒蛇基维。如何将标签文本更改为已按下按钮上的文本?
- oracle - ORA-29285: 文件写入错误
- npm - NPM 总是安装最新的预发布版本
- windows - 关于 hadoop winutils.exe 的 Accumulo 数据存储抛出异常
- regex - 带有 / 或 - 的字母数字的正则表达式
- vue.js - 使用路由处理单击另一个组件内的组件?
- javascript - 在 d3.js 中聚类气泡
- android - 如何从 View Pager Fragment 打开 Fragment
- ruby - 如果值不在另一个哈希中,则从循环中的哈希中删除值