I am going to execute a Process (lame.exe) to encode a WAV file to MP3.
I want to process the STDOUT and STDERR of the process to display progress information.
There is an MSDN example for this... Here is a simplified version:
var StdOut = "";
var StdErr = "";
var stdout = new StringBuilder();
var stderr = new StringBuilder();
var psi = new ProcessStartInfo();
psi.FileName = @"something.exe";
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
var proc = new Process();
proc.StartInfo = psi;
proc.OutputDataReceived += (sender, e) => { stdout.AppendLine(e.Data); };
proc.ErrorDataReceived += (sender, e) => { stderr.AppendLine(e.Data); };
proc.Start();
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
proc.WaitForExit(10000); // per sachin-joseph's comment
StdOut = stdout.ToString();
StdErr = stderr.ToString();