Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process.Start() get errors from command prompt window

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

like image 812
loviji Avatar asked Apr 25 '10 17:04

loviji


People also ask

How can I see errors in CMD?

As a shortcut you can press the Windows key + R to open a run window, type cmd to open a, command prompt window. Type eventvwr and click enter.

What does Process start do?

Start(ProcessStartInfo)Starts the process resource that is specified by the parameter containing process start information (for example, the file name of the process to start) and associates the resource with a new Process component.

What is process start in C#?

Start(String) Starts a process resource by specifying the name of a document or application file and associates the resource with a new Process component. public: static System::Diagnostics::Process ^ Start(System::String ^ fileName); C# Copy.


1 Answers

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.

like image 149
Mark Byers Avatar answered Sep 19 '22 13:09

Mark Byers