Process.RedirectStandardOutput not working
I have a problem redirecting the application's standard output. It seems to be some kind of bug in .NET.
I run Live555ProxyServer , but I don't get any output even when the console that launches has written output. This code works with any other console application, but not this one.
void StartProcess()
{
var process = new Process();
process.StartInfo.FileName = @"live555ProxyServer.exe";
process.StartInfo.Arguments = "-R";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.OutputDataReceived += process_OutputDataReceived;
process.Start();
process.BeginOutputReadLine();
}
void process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
Debug.WriteLine(e.Data);
}
The source code for this application can be found here
+3
source to share
1 answer
This is because all the output goes stderr
instead stdout
, see source code
You have to add a handler for Process.ErrorDataReceived
and call Process.BeginErrorReadLine
and everything will start smoothly.
+6
source to share