Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process.RedirectStandardOutput does not work

Tags:

c#

output

process

I have a problem redirecting standard output of an application. It seems like this is some kind of bug in .NET.

I'm running Live555ProxyServer but I don't get any output even when console which starts does have a written output. This code works with any other console application but not with 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 of that application can be found here

like image 961
Teamol Avatar asked Jan 08 '23 11:01

Teamol


1 Answers

That is because all output goes to stderr instead of stdout, see source code

You should add a handler for Process.ErrorDataReceived and call Process.BeginErrorReadLine and things will start going smoothly.

like image 117
huysentruitw Avatar answered Jan 15 '23 07:01

huysentruitw