how to execute console application from windows form?

后端 未结 8 930
感情败类
感情败类 2020-12-09 11:43

I want to run a console application (eg app.exe) from a windows form load event. I\'v tried System.Diagnostics.Process.Start(), But after it opens app.exe, it closes it immi

8条回答
  •  情歌与酒
    2020-12-09 12:09

    If you have control over app.exe, you should be aware of how it functions so I will assume that you do not have control over it's inner workings. In that case, you can try passing a help flag which may or may not give you more info on how to call app.exe. Try something like this:

    private startApp()
    {
        string command = " -h"; //common help flag for console apps
        System.Diagnostics.Process pRun;
        pRun = new System.Diagnostics.Process();
        pRun.EnableRaisingEvents = true;
        pRun.Exited += new EventHandler(pRun_Exited);
        pRun.StartInfo.FileName = "app.exe";
        pRun.StartInfo.Arguments = command;
        pRun.StartInfo.WindowStyle =  System.Diagnostics.ProcessWindowStyle.Normal
    
        pRun.Start();
        pRun.WaitForExit();
    }
    private void  pRun_Exited(object sender, EventArgs e)
    {
        //Do Something Here
    }
    

提交回复
热议问题