简体   繁体   English

Process.RedirectStandardOutput不起作用

[英]Process.RedirectStandardOutput does not work

I have a problem redirecting standard output of an application. 我在重定向应用程序的标准输出时遇到问题。 It seems like this is some kind of bug in .NET. 看起来这是.NET中的某种错误。

I'm running Live555ProxyServer but I don't get any output even when console which starts does have a written output. 我正在运行Live555ProxyServer,但即使启动的控制台确实有写入输出,我也没有得到任何输出。 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 该应用程序的源代码可以在这里找到

That is because all output goes to stderr instead of stdout , see source code 这是因为所有输出都转到stderr而不是stdout ,请参阅源代码

You should add a handler for Process.ErrorDataReceived and call Process.BeginErrorReadLine and things will start going smoothly. 您应该为Process.ErrorDataReceived添加一个处理程序并调用Process.BeginErrorReadLine ,事情将顺利开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM