Problems getting desired output from Process.Start()

后端 未结 2 1786
忘了有多久
忘了有多久 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:38

    See the docs on RedirectStandardOutput. Waiting for the child process to end before reading the output can cause a hang.

    It particular, the example says not to do what you have done:

     Process p = new Process();
     // Redirect the output stream of the child process.
     p.StartInfo.UseShellExecute = false;
     p.StartInfo.RedirectStandardOutput = true;
     p.StartInfo.FileName = "Write500Lines.exe";
     p.Start();
     // Do not wait for the child process to exit before
     // reading to the end of its redirected stream.
     // p.WaitForExit();
     // Read the output stream first and then wait.
     string output = p.StandardOutput.ReadToEnd();
     p.WaitForExit();
    

    You should use the events OutputDataReceived and possibly ErrorDataReceived and update the progress bar in the handler.

提交回复
热议问题