views:

115

answers:

3

Hello, 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

+2  A: 

You're probably looking for the StandardError property.

SLaks
+2  A: 

Process.StandardError Property:

Gets a stream used to read the error output of the application.

This should do what you want.

Note

To use StandardError, you must set ProcessStartInfo.UseShellExecute to false, and you must set ProcessStartInfo.RedirectStandardError to true. Otherwise, reading from the StandardError stream throws an exception.

ChrisF
+2  A: 

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.

Mark Byers