how to execute console application from windows fo

2019-01-17 22:13发布

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 immidiately.

Is there any way that I can run app.exe and leave it open?

8条回答
够拽才男人
2楼-- · 2019-01-17 22:57

If you are just wanting the console window to stay open, you could run it with something like this command:

System.Diagnostics.Process.Start( @"cmd.exe", @"/k c:\path\my.exe" );
查看更多
Lonely孤独者°
3楼-- · 2019-01-17 22:59

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.

查看更多
登录 后发表回答