C# 为什么这个方法不重定向我从.exe[ffmpeg]的输出?

C# 为什么这个方法不重定向我从.exe[ffmpeg]的输出?,c#,redirect,ffmpeg,console-application,C#,Redirect,Ffmpeg,Console Application,我的方法是: public static string StartProcess(string exePathArg, string argumentsArg, int timeToWaitForProcessToExit) { string retMessage = ""; using (Process p = new Process()) { p.StartInfo.FileName = exePathArg;

我的方法是:

public static string StartProcess(string exePathArg, string argumentsArg, int timeToWaitForProcessToExit)
    {
        string retMessage = "";

        using (Process p = new Process())
        {
            p.StartInfo.FileName = exePathArg;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.Arguments = argumentsArg;
            p.StartInfo.UseShellExecute = false;



            try
            {
                p.Start();
                StreamReader myOutput = p.StandardOutput;

                retMessage = "STANDARD OUTPUT: " +  myOutput.ReadToEnd();

                p.WaitForExit(timeToWaitForProcessToExit);
            }
            catch (Exception ex)
            { 
                retMessage = "EXCEPTION THROWN: " + ex.ToString();

            }
            finally
            {
                try
                {
                    p.Kill();
                }
                catch { }
            }
        }

        return retMessage;
    }
但它不会将我的输出重定向到retMessage。有人有什么想法吗?我在一个bat文件中测试了参数,输出肯定是输出

干杯, 皮特

我的猜测(同意dtb的评论): AFAIK
ffmpeg
使用stdout输出二进制数据(多媒体、快照等),stderr用于日志记录。在您的示例中,您使用标准输出

因此,将代码更改为:

    p.StartInfo.RedirectStandardError = true;
    ...
    string log = p.StandardError.ReadToEnd();

它应该可以解决您的问题。

也许该过程不会写入StandardOutput,而只写入StandardError?太好了!就这样了,谢谢你的帖子真的帮了我的忙,我从来没有想过要检查,再次感谢!我对ffmpeg的输出也有同样的问题。StandardOutput返回空,所有输出来自standardError。。我希望这能节省别人的时间。