GurdeepS
GurdeepS

Reputation: 67213

Getting exit code from a batch file

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

Upvotes: 3

Views: 3229

Answers (2)

HABJAN
HABJAN

Reputation: 9328

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.

Upvotes: 6

Daniel Ives
Daniel Ives

Reputation: 717

Process.Start() returns a Process instance. Process has an ExitCode property.

Upvotes: 2

Related Questions