Process.RedirectStandardOutput does not work

社会主义新天地 提交于 2020-08-27 21:21:46

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/29967590/process-redirectstandardoutput-does-not-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!