how to execute console application from windows form?

后端 未结 8 920
感情败类
感情败类 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 11:52

    Try doing this:

            string cmdexePath = @"C:\Windows\System32\cmd.exe";
            //notice the quotes around the below string...
            string myApplication = "\"C:\\Windows\\System32\\ftp.exe\"";
            //the /K keeps the CMD window open - even if your windows app closes
            string cmdArguments = String.Format("/K {0}", myApplication);
            ProcessStartInfo psi = new ProcessStartInfo(cmdexePath, cmdArguments);
            Process p = new Process();
            p.StartInfo = psi;
            p.Start();
    

    I think this will get you the behavior you are trying for. Assuming you weren't just trying to see the output in the command window. If you just want to see the output, you have several versions of that answer already. This is just how you can run your app and keep the console open.

    Hope this helps. Good luck.

提交回复
热议问题