Problems getting desired output from Process.Start()

后端 未结 2 1784
忘了有多久
忘了有多久 2021-01-25 18:47

I am working on an application that calls several command line applications to do some post processing on some video files.

Right now I am trying to use Comskip to ide

2条回答
  •  伪装坚强ぢ
    2021-01-25 19:36

    You must set following:

         process.StartInfo.RedirectStandardOutput = true;
         process.StartInfo.RedirectStandardError = true;
         process.StartInfo.UseShellExecute = false;
         process.OutputDataReceived += new DataReceivedEventHandler(ReadOutput);
         process.ErrorDataReceived += new DataReceivedEventHandler(ErrorOutput);
    
         process.Start();
         process.BeginOutputReadLine();
         process.BeginErrorReadLine();
         process.WaitForExit();
    

    and catch the output in ReadOutput and ErrorOutput

      private static void ErrorOutput(object sender, DataReceivedEventArgs e)
      {
         if (e.Data != null)
         {
            stdout = "Error: " + e.Data;
         }
      }
    
      private static void ReadOutput(object sender, DataReceivedEventArgs e)
      {
         if (e.Data != null)
         {
            stdout = e.Data;
         }
      }
    

提交回复
热议问题