Process.RedirectStandardOutput不起作用

Tea*_*mol 3 c# process output

我在重定向应用程序的标准输出时遇到问题.看起来这是.NET中的某种错误.

我正在运行Live555ProxyServer,但即使启动的控制台确实有写入输出,我也没有得到任何输出.此代码适用于任何其他控制台应用程序,但不适用于此代码.

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);
}
Run Code Online (Sandbox Code Playgroud)

该应用程序的源代码可以在这里找到

huy*_*itw 6

这是因为所有输出都stderr代替stdout,请参阅源代码

你应该添加一个处理程序Process.ErrorDataReceived和调用Process.BeginErrorReadLine,事情将开始顺利进行.