Guest User

Untitled

a guest
Jul 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. public static void ExecuteCommand(String checkOutFile)
  2. {
  3. int ExitCode;
  4. ProcessStartInfo ProcessInfo;
  5. Process process;
  6.  
  7. ProcessInfo = new ProcessStartInfo(checkOutFile);
  8. ProcessInfo.CreateNoWindow = true;
  9. ProcessInfo.UseShellExecute = false;
  10. ProcessInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(checkOutFile);
  11. // *** Redirect the output ***
  12. ProcessInfo.RedirectStandardError = true;
  13. ProcessInfo.RedirectStandardOutput = true;
  14.  
  15. process = Process.Start(ProcessInfo);
  16. process.WaitForExit();
  17.  
  18. // *** Read the streams ***
  19. string output = process.StandardOutput.ReadToEnd();
  20. string error = process.StandardError.ReadToEnd();
  21.  
  22. ExitCode = process.ExitCode;
  23.  
  24. Console.WriteLine("output>>" + (String.IsNullOrEmpty(output) ? "(none)" : output));
  25. Console.WriteLine("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error));
  26. Console.WriteLine("ExitCode: " + ExitCode.ToString(), "ExecuteCommand");
  27. process.Close();
  28. }
Add Comment
Please, Sign In to add comment