how to execute console application from windows form?

后端 未结 8 955
感情败类
感情败类 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:02

    You have one of two problems, given your master/slave application setup:

    1. Your master app is opening, displaying a form, that form runs the slave app and closes immediately, even though the slave app is still running.
    2. Your master app is opening, displaying a form, that form runs the slave app which closes immediately.

    For the first problem, you need to wait/block for the process to complete (i.e. Process.WaitForExit().

    For the second problem, it sounds like the slave app has done what it needs to (or thrown an exception) and is closing immediately. Try running it with the same parameters from a command prompt and check the output.

提交回复
热议问题