C# - How to call an exe added into project solution

混江龙づ霸主 提交于 2019-12-06 01:39:18

问题


So I added an EXE to my project's solution. The EXE does some stuff and outputs data via stdout. I want to capture the output, but more importantly how do I execute that EXE within my program?


回答1:


Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "myExec.exe";
p.Start();



回答2:


Process.Start. To capture stdout you need to redirect it via ProcessStartInfo - there is an example on MSDN. Make sure also that the exe is marked to be copied to the output directory (bin/release etc).

If you need to read from both stdout and stderr it gets tricky (with a naïve implementation there is a risk of deadlock due to buffering etc)... here's an example using worker threads.



来源:https://stackoverflow.com/questions/319304/c-sharp-how-to-call-an-exe-added-into-project-solution

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!