How to start processes synchronously, focusing on the same conclusion?

I have a .Net application that needs to run multiple executables. I use the Process class, but Process.Start is not blocking. I need the first process to complete before the second launch. How can i do this?

In addition, I would like all processes to be displayed in the same console window. Be that as it may, they seem to open their windows. I'm sure I can use the StandardOutput stream to write to the console, but how can I suppress the default output?

+6
source share
1 answer

I believe what you are looking for:

Process p = Process.Start("myapp.exe");
p.WaitForExit();

To output:

StreamReader stdOut = p.StandardOutput;

, .

, :

ProcessStartInfo pi = new ProcessStartInfo("myapp.exe");
pi.CreateNoWindow = true;
pi.UseShellExecute = true;

// Also, for the std in/out you have to start it this way too to override:
pi.RedirectStandardOutput = true; // Will enable .StandardOutput

Process p = Process.Start(pi);
+11

All Articles