2010-11-22 53 views
5

我的方法:为什么这种方法重定向我的输出从.exe [ffmpeg]?

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

干杯, 皮特

+2

也许进程不会写入StandardOutput,而只写入StandardError? – dtb 2010-11-22 15:03:47

回答

8

我猜想(与DTB的评论表示赞同):据我所知 标准输出ffmpeg使用管道出二进制数据(多媒体,快照等)和标准错误用于日志记录。在你的例子中你使用stdout。

所以,你的代码更改为:

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

,它应该解决您的问题。

+0

太棒了!多数民众赞成在排序它感谢帖子真的帮助我永远不会检查,再次感谢! – Exitos 2010-11-23 09:16:16

相关问题