Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


How to Check the Exit Status Code of a Program

Keywords: 	 IntControl 64  exit code

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:

Assuming you are using the current 98 release of WinBatch AND one of the RunWait family of functions, then you can use:

	IntControl 64
Here's the documentation for it.

IntControl (64, 0, 0, 0, 0)

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.

If you have an older version, then I have a different Rube Goldberg type scheme to get the errorcode. Look in your WinBatch/System subdirector for the files DOSERROR.BAT and DOSERROR.WBT for an example of how it is done.


Article ID:   W12976
Filename:   How to Check Exit Status Code of Program.txt