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
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With