Guest User

Untitled

a guest
Feb 10th, 2011
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. Process myProcess = new Process();
  2.  
  3. myProcess.StartInfo.WorkingDirectory = workingDirectory;
  4. myProcess.StartInfo.FileName = programFilePath;
  5. myProcess.StartInfo.Arguments = commandLineArgs;
  6. myProcess.StartInfo.UseShellExecute = false;
  7. myProcess.StartInfo.CreateNoWindow = true;
  8. myProcess.StartInfo.RedirectStandardOutput = true;
  9. myProcess.StartInfo.RedirectStandardError = true;
  10. myProcess.Start();
  11.  
  12. StreamReader sOut = myProcess.StandardOutput;
  13. StreamReader sErr = myProcess.StandardError;
  14.  
  15. try
  16. {
  17. string str;
  18.  
  19. // reading errors and output async...
  20.  
  21. while ((str = sOut.ReadLine()) != null && !sOut.EndOfStream)
  22. {
  23. logMessage(str + Environment.NewLine, true);
  24. Application.DoEvents();
  25. sOut.BaseStream.Flush();
  26. }
  27.  
  28. while ((str = sErr.ReadLine()) != null && !sErr.EndOfStream)
  29. {
  30. logError(str + Environment.NewLine, true);
  31. Application.DoEvents();
  32. sErr.BaseStream.Flush();
  33. }
  34.  
  35. myProcess.WaitForExit();
  36. }
  37. finally
  38. {
  39. sOut.Close();
  40. sErr.Close();
  41. }
Advertisement
Add Comment
Please, Sign In to add comment