WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Error Codes

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Check the Exit Status Code of a Program

Keywords: 	 IntControl 64  exit code  getexitcode error level errorlevel

Question:

I know how to set the exit code for the WinMain() function of a WinBatch script via IntControl(1000,...). However, if I run an executable via any of RunXXX commands, I have no way to determine what the exit code of the program is.

Does WinBatch have any feature similar to the DOS "errorlevel" that works in the desired manner? I can use LastError() to get the last internal WinBatch error code, but I cannot seem to get the exit code for external programs that are launched by WinBatch.

Answer:

Yes, assuming you are using one of the RunWait family of functions, then you can use IntControl 64.

IntControl 64 gets the exit code returned by the last program run. This function gets the exit code (also known as the "errorlevel") that was returned by the program that was most-recently run using RunWait (or using RunShell with the @WAIT flag specified). If no program has been run, or if the last-run program was not run in @WAIT mode, this function will return 99999.

RunWait('c:\sample.bat', '')
exitcode = IntControl (64, 0, 0, 0, 0)

Also you can use the RunShell function with the @GETEXITCODE wait flag.

RunShell('c:\sample.bat', '', '', @NORMAL, @GETEXITCODE)
If the @GETEXITCODE parameter is used, the exit code of an application that is launched with the RunShell function will be returned. This is the same as specifying @WAIT, except that on success the function will return the exit code of the application that was launched.


Article ID:   W12976
Filename:   How to Check Exit Status Code of Program.txt
File Created: 2013:01:08:15:19:20
Last Updated: 2013:01:08:15:19:20