Diagnostics.Process - Error Handling

G

Guest

Hello Guys:

How would I be able to check if a .bat file I call had an error associated
with it? I have the following code to shell out to a batch file. However:
if an error occured: how would I be able to trap for this error? Is it as
simple as a try...catch? I have been uncessful in my attempts.

System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "uploadin.bat"
process.Start();

Thanks
Andy
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Andy said:
Hello Guys:

How would I be able to check if a .bat file I call had an error associated
with it? I have the following code to shell out to a batch file.
However:
if an error occured: how would I be able to trap for this error? Is it
as
simple as a try...catch? I have been uncessful in my attempts.

System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "uploadin.bat"
process.Start();


You have to check Process.ExitCode:

process.Start();
process.WaitForExit()
if ( process.ExitCode == 0 )
Console.Write( "OK");
else
//error occured
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top