2

I am starting a process using Process.Start(ProcessStartInfo). It currently brings up a console window and the output of the process is displayed there until the process completes, in which case the console window closes automatically.

The process outputs a lot of text, so I do not just want to redirect this output to a string, like examples I have found so far.

How can I get the text of the console output to go into a text log file?

ProcessStartInfo myPSI = new ProcessStartInfo();
myPSI.FileName = myFileName;
myPSI.Arguments = myArgs;
myPSI.CreateNoWindow = false;
myPSI.UseShellExecute = false;
myPSI.WindowStyle = ProcessWindowStyle.Hidden;

try
{
  using (Process exeProcess = Process.Start(myPSI))
  {
    exeProcess.WaitForExit();
  }
}
catch
{
}
jkh
  • 3,618
  • 8
  • 38
  • 66

2 Answers2

1

You need to use output redirection. See here: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx

Ross Dargan
  • 5,876
  • 4
  • 40
  • 53
0

You can redirect the output to whatever you want... for example a stream... you can even process the output in a separate thread if you want to - for source code and details see http://www.codeproject.com/KB/threads/ReadProcessStdoutStderr.aspx

Yahia
  • 69,653
  • 9
  • 115
  • 144