Process.Start() get errors from command prompt window

前端 未结 3 801
梦如初夏
梦如初夏 2020-12-19 00:35

I\'m trying to Start command promt process with args. Now I want to obtain information about errors if they exist.

someProcess = System.Diag         


        
3条回答
  •  醉梦人生
    2020-12-19 01:05

    The other answers are correct. Here is some code you could use:

    ProcessStartInfo startInfo = new ProcessStartInfo(cmd, args);
    startInfo.UseShellExecute = false;
    startInfo.RedirectStandardError = true;
    Process someProcess = Process.Start(startInfo);
    string errors = someProcess.StandardError.ReadToEnd();
    

    Note that if the file is not found you won't get an error on standard error. You will get an exception instead.

提交回复
热议问题