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

Tutorials
plus

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

Exit Codes in WinBatch

 Keywords: Exit Code ExitCode Result Return

Exit Code (sometimes referred to as a return status or return code).

The exit command is used to terminate a script. By default the exit code that is sent to the parent process (shell) is zero. However, WinBatch can also return a specific exit code value, which is available to the script's parent process.

Every function in WinBatch returns a result. A successful command returns a 1, while an unsuccessful script returns a ZERO value or an error. However, well-behaved scripts should return a ZERO exit code upon successful completion. WinBatch always returns a zero, unless otherwise specified.

You can use the IntControl 1000 function to modify the exit code. The last IntControl 1000 command executed in the script determines the exit status. The Exit Code values should be an integer in the 0 - 255 range.

When a script ends with an exit with no IntControl 1000 the exit code will be ZERO.

;{WILCOMMANDS}
Exit
; Exit code will be zero

When a script ends with no exit with no IntControl 1000 the exit code will be ZERO.

;{WILCOMMANDS}
; Exit code will be zero

When a script ends calling IntControl 1000 the exit code will be the value specified in the last IntControl 1000 call.

exitcode = AskLine( "Hello", "Enter Exit Code", "13")
IntControl( 1000, exitcode, 0, 0, 0)
Exit
Here's another example:
;***************************************************************************
;**
;** exit code 123 on failure and zero for success
;**
;***************************************************************************

; Set exit code to some known value until code completes
exitcode = 123 ; assume failure
IntControl(1000, exitcode, 0, 0, 0)

;{WILCOMMANDS}

; Set exit code back to ZERO just before exit
exitcode = 123 ; assume failure
IntControl(1000, 0, 0, 0, 0)
Exit

Article ID:   W17510
Filename:   Exit Codes in WinBatch.txt
File Created: 2011:03:18:12:26:27
Last Updated: 2011:03:18:12:55:58