【问题标题】:Why doesnt this method redirect my output from .exe [ffmpeg]?为什么此方法不从 .exe [ffmpeg] 重定向我的输出?
【发布时间】:2011-05-13 21:41:14
【问题描述】:

我有方法:

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文件中测试了参数,输出肯定是输出。

干杯, 皮特

【问题讨论】:

  • 也许进程不写入 StandardOutput 而只写入 StandardError?

标签: c# redirect ffmpeg console-application


【解决方案1】:

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

所以,把你的代码改成:

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

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

【讨论】:

  • 太棒了!就是这样,谢谢你的帖子真的很有帮助,我从来没想过要检查,再次感谢!
  • 我对 ffmpeg 的输出有同样的问题。 StandardOutput 返回空,所有输出都来自standardError..我希望这会节省别人的时间。
猜你喜欢
  • 2018-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-08
相关资源
最近更新 更多