代码之家  ›  专栏  ›  技术社区  ›  Exitos

为什么此方法不重定向.exe[ffmpeg]中的输出?

  •  5
  • Exitos  · 技术社区  · 16 年前

    我有办法:

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

    干杯, 皮特

    1 回复  |  直到 16 年前
        1
  •  8
  •   Oleks    13 年前

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

    所以,将代码更改为:

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

    它应该能解决你的问题。