unexpected double ampersand/pipe behavior when chaining batch script

|| and && respond to the return code of the previous command (the last executed command on the left). All programs exit with an error code, regardless of context.

EXIT /B 1 sets the batch ERRORLEVEL, which is strictly a cmd.exe concept.

The return code and ERRORLEVEL are not the same thing!

When a batch file is executed, the exiting ERRORLEVEL is only returned as the return code if the batch file was executed via CALL.

When a batch file is executed without CALL, && and || respond to the last command executed within the script.

EXIT /B 1 sets ERRORLEVEL to 1, but the command executed successfully, so the return code is 0.

When CALL is used, the CALL command looks at the ERRORLEVEL after the script terminates, and sets the return code to the ERRORLEVEL.

Tags:

Batch File

Cmd