Passing back the ERRORLEVEL

eryk sun eryksun at gmail.com
Sat Dec 29 04:05:47 EST 2018


On 12/28/18, Gisle Vanem <gisle.vanem at gmail.com> wrote:
> I have trouble understanding why a 'sys.exit(2)' is
> *not* passed back to the CMD shell in this little example:
>
> ----- c:\py_cmd_test.cmd ------
> @%WinDir%\py.exe -2 -x %~dp0py_cmd_test.cmd & exit /b %ERRORLEVEL%

%ERRORLEVEL% gets expanded in the initial parsing before this line is
executed, at which time it is 0. Because of the /b argument, you're
not actually exiting CMD and have no reason to change the error value.
Just use `exit /b`.

Why use CMD as a launcher when you have py.exe with shebang support?



More information about the Python-list mailing list