Process start

I am using VSTS 2008 + C # + .Net 3.5 to develop a console application. And I want to start the external process (exe file) from my C # application, and I want the current C # application to be blocked until the external process stops, and I also want to get the return code of the external process.

Any ideas how to implement this? Appreciate if some code examples.

+6
c # visual-studio-2008
source share
3 answers
using (var process = Process.Start("test.exe")) { process.WaitForExit(); var exitCode = process.ExitCode; } 
+9
source share
  public static String ShellExec( String pExeFN, String pParams, out int exit_code) { System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(pExeFN, pParams); psi.RedirectStandardOutput = true; psi.UseShellExecute = false; // the process is created directly from the executable file psi.CreateNoWindow = true; using (System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi)) { string tool_output = p.StandardOutput.ReadToEnd(); p.WaitForExit(); exit_code = p.ExitCode; return tool_output; } } 
+2
source share
+1
source share

All Articles