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

DOS

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

WinBatch and Return Code Values

Keywords:	 return code value return codes	 IntControl(64... Intcontrol(1000...

Question:

Does WinBatch return a value when its finished? I would like to get a return code back to my server, because that is the only way we can determine if the batch process on the NT server completed successfully or unsuccessfully.

Answer:

Windows programs, generally speaking, don't return useable exit codes, and WinBatch is no exception.

Unlike the DOS spawn[...] functions, which return the value that was returned by the child process's main() function (or -1 on error), the equivalent Windows API functions (WinExec and LoadModule) return the loaded module instance (or a value <32 on error), so there is no easy way for the calling program to determine the return value from WinMain [the Windows equivalent of main()].

According to the Windows SDK documentation, "The return value from WinMain is not currently used by Windows". It's *possible* for Windows programs to return a value, but in practice they don't.

Despite all this, the Intcontrol(1000...) function in Winbatch might be useful, if you know what the code is you're looking for, and can enter the desired return code first.

However, note that this return code can ONLY be read by DOS batch files, not Winbatch itself or other Windows applications. Make sure you launch Winbatch with a start /w on the command line ala...

   start /w abc.exe
  • Test with simply WinBatch files:
    	a=AskLine("Hello","Enter Return code","13")
    	IntControl(1000,1,0,0,0)
    	exit 
    

    Here's another example:

    	:toptop
    	retcode=AskLine("hello", "Enter desired return code", 123)
    	if !IsInt(retcode) then Message(("EEEK", "retcode must be an integer less than 256")
    	if !IsInt(retcode) then goto toptop
    
    	if retcode<0 || retcode > 255 then Message("EEEEK", "retcode must be an integer less than 256")
    	if retcode<0 || retcode > 255 then goto toptop
    
    	IntControl(1000, retcode, 0, 0, 0)
    
    	;then this retcode can be passed to a DOS batch file.
    
    Otherwise, from another winbatch:

    RunWait the exe, then use IntControl(64... to retrieve the exit code.

    The IntControl(64...) 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.

    Related Question:

    I intend to use WinBatch under NT Server to run Micro Focus COBOL programs. Micro Focus permits the use of return codes. Is their a way to "Run" a micro focus program from WinBatch passing it parameters and ==> Receive a "return Code" back from the Micro Focus COBOL program that WinBatch can recognize and work with it ? If not, I guess I must use DDE or pass data via files or environmental variables.

    Answer:

    Is MicroFocus COBOL a DOS/Console app?

    If so, See the DOSERROR.WBT and DOSERROR.BAT file in your WINBATCH/SAMPLES subdirectory to show how to return a DOS errorlevel to WinBatch.

    If it is a WinApp, launch it via the DOSERROR.BAT file anyway, using the:

    	START /w mfcobolwhatever.exe
    
    This is the console START command in NT.
    Article ID:   W12909
    
    Filename:   WinBatch and Return Code Values .txt
    File Created: 2001:01:02:14:35:50
    Last Updated: 2001:01:02:14:35:50