C # - How to call exe in design solution

So, I added the EXE to my design solution. The exe does some things and outputs data via stdout. I want to capture the output, but more importantly, how do I execute this EXE in my program?

+6
c # executable
source share
2 answers
Process p = new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = "myExec.exe"; p.Start(); 
+7
source share

Process.Start . To capture stdout, you need to redirect it through ProcessStartInfo - there is an example on MSDN . Also make sure that exe is marked for copying to the output directory (bin / release, etc.).

If you need to read from both stdout and stderr, it becomes complicated (with the highest implementation there is a risk of a deadlock due to buffering, etc.) ... here is an example using workflows.

+3
source share

All Articles