I'm running a python program on WindowsXP. How can I obtain the exit code after my program ends?
From a Windows command line you can use:
echo %ERRORLEVEL%
For example:
C:\work>python helloworld.py
Hello World!
C:\work>echo %ERRORLEVEL%
0
How do you run the program?
Exit in python with sys.exit(1)
If you're in CMD or a BAT file you can access the variable %ERRORLEVEL% to obtain the exit code.
For example (batch file):
IF ERRORLEVEL 1 GOTO LABEL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With