Frage

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
{
}
War es hilfreich?

Lösung

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

Andere Tipps

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top