Passing back the ERRORLEVEL
Gisle Vanem
gisle.vanem at gmail.com
Fri Dec 28 23:16:41 EST 2018
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%
# The '-x' is for Python to skip the 1st line of this file.
import sys
print ("Hello, I am %s; %s" % (sys.argv[0], sys.version_info))
sys.exit (2)
--------
Executing this in a 4NT shell (from JPsoft), correctly reports:
c:\> py_cmd_test.cmd & echo %errorlevel
Hello, I am C:\py_cmd_test.cmd; sys.version_info(major=2, minor=7, micro=15, releaselevel='final', serial=0)
2
But the junk-ware cmd.exe does not:
C:\>py_cmd_test.cmd & echo %ERRORLEVEL%
Hello, I am C:\py_cmd_test.cmd; sys.version_info(major=2, minor=7, micro=15, releaselevel='final', serial=0)
0
Anybody here who can spot the problem?
Same issue with 'py -3'. I'm on Windows-10.
--
--gv
More information about the Python-list
mailing list