471,348 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Diagnostics.Process - Error Handling

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
Feb 15 '06 #1
1 6703
Hi,

"Andy" <An**@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.com...
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

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Feb 15 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Morten | last post: by
1 post views Thread by solex | last post: by
5 posts views Thread by Rob R. Ainscough | last post: by
1 post views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.