Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

someProcess = System.Diagnostics.Process.Start(cmd, someArgs);

Best regards, loviji

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
536 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...