Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting exit code from a batch file

Tags:

c#

In C#, how can I capture the exit code of batch file I launch via Process.Start()?

Also, is there any limitation of running a batch file via Windows Service (The service being the invoker)?

Thanks

like image 836
GurdeepS Avatar asked Aug 12 '26 09:08

GurdeepS


1 Answers

Sample:

Process prc = Process.Start(@"C:\file.bat");
prc.WaitForExit();
int exitCode = prc.ExitCode;

If you will try to start some process that interacts with UI from Windows Service you will run into a "Services isolation in Session 0" problem.

like image 91
HABJAN Avatar answered Aug 15 '26 00:08

HABJAN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!