2010-11-22 5 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 करने के लिए अपने उत्पादन अनुप्रेषित नहीं करता है। कोई भी विचार? मैंने बैट फ़ाइल में तर्कों का परीक्षण किया और आउटपुट निश्चित रूप से आउटपुट है।

चीयर्स, पीट

+2

शायद प्रक्रिया मानक आउटपुट पर नहीं बल्कि केवल मानक त्रुटि के लिए लिखती है? – dtb

उत्तर

8

मेरा अनुमान है (DTB की टिप्पणी से सहमत): AFAIK ffmpeg पाइप बाहर बाइनरी डेटा (मल्टीमीडिया, फोटो, आदि) और stderr करने के लिए stdout का उपयोग करता है प्रवेश के प्रयोजनों के लिए प्रयोग किया जाता है। आपके उदाहरण में आप stdout का उपयोग करते हैं।

तो, करने के लिए कोड आप बदल:

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

और यह आपकी समस्या का समाधान करना चाहिए।

+0

बढ़िया! जिसने पोस्ट को वास्तव में मदद के लिए धन्यवाद दिया, मैंने कभी जांच नहीं की, फिर भी धन्यवाद! – Exitos

+0

मुझे ffmpeg के आउटपुट के साथ एक ही समस्या थी। StandardOutput खाली आता है, सभी आउटपुट मानक त्रुटि से आता है .. मुझे उम्मीद है कि यह किसी और के समय को बचाएगा। – dvdmn

संबंधित मुद्दे