简体   繁体   English

从后面的代码启动命令行 exe (ngrok) 的正确方法

[英]Correct way to start a command line exe (ngrok) from code behind

Im tryng to sart ngrok from a WPF C# app.我试图从 WPF C# 应用程序中启动 ngrok。

The desired result would be windows command line opening and ngrok starting up as if I had manually started it.所需的结果将是 windows 命令行打开和 ngrok 启动,就像我手动启动它一样。

Im getting an exception: System.InvalidOperationException我得到一个异常:System.InvalidOperationException

private async void StartNgrok()
    {
        string ExePath = "C:\\Users\\mmcca\\ngrok.exe";
        string Args = "\"http 55678 -host-header=\"localhost: 55678\"";

        try
        {
            var proc = Process.Start(ExePath, Args);
        }
        catch (Exception ex)
        {
            // Throwing - System.InvalidOperationexception
        }

What is the correct way to start a command line exe from code behind?从后面的代码启动命令行 exe 的正确方法是什么?

You could try declaring ngrok as a Process, and then starting it this way - this has worked for me in the past:您可以尝试将 ngrok 声明为进程,然后以这种方式启动它 - 这在过去对我有用:

Process ngrok = new Process();
ngrok.StartInfo.FileName   = "C:\\Users\\mmcca\\ngrok.exe";
ngrok.StartInfo.Arguments = "\"http 55678 -host-header=\"localhost: 55678\"";
ngrok.Start();

Let me know how you get on with this.让我知道你如何处理这件事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM