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?
+3
A:
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.
Marc Gravell
2008-11-25 23:54:16
+4
A:
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "myExec.exe";
p.Start();
Alan
2008-11-25 23:55:13
this answer worked. thanks!
2008-11-26 00:18:52
although the relative file path will only work if the Current Working Directory hasn't changed...
David Rogers
2009-10-27 19:34:41