Process.start: how to get the output?

后端 未结 9 1411
無奈伤痛
無奈伤痛 2020-11-21 23:56

I would like to run an external command line program from my Mono/.NET app. For example, I would like to run mencoder. Is it possible:

  1. To get
9条回答
  •  长情又很酷
    2020-11-22 00:52

    You can log process output using below code:

    ProcessStartInfo pinfo = new ProcessStartInfo(item);
    pinfo.CreateNoWindow = false;
    pinfo.UseShellExecute = true;
    pinfo.RedirectStandardOutput = true;
    pinfo.RedirectStandardInput = true;
    pinfo.RedirectStandardError = true;
    pinfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
    var p = Process.Start(pinfo);
    p.WaitForExit();
    Process process = Process.Start(new ProcessStartInfo((item + '>' + item + ".txt"))
    {
        UseShellExecute = false,
        RedirectStandardOutput = true
    });
    process.WaitForExit();
    string output = process.StandardOutput.ReadToEnd();
    if (process.ExitCode != 0) { 
    }
    

提交回复
热议问题