Dear Stack Overflow Community,
I'm trying to communicate with the Ngrok console using C #. Unfortunately "StartInfo.Arguments" does not work. For example, if I write "StartInfo.Arguments =" ngrok in the c# code", the ngrok help text does not appear, but" ERROR: Unrecognized command: ngrok "in the log. But if I open the console myself and write in" ngrok "it works.
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();
}
you are using "ngrok" as argument. That is the same as you would write ngrok.exe ngrok
in the console. The command is not recognized by ngrok. Try to use proper arguments for example compiler.StartInfo.Arguments = "http 80";
or just leave it blank. If you want to use ngrok with the port 80 over http your code has to look like that:
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();
}