Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get the exit code for python program

Tags:

python

I'm running a python program on WindowsXP. How can I obtain the exit code after my program ends?

like image 839
phoenix24 Avatar asked Sep 29 '09 10:09

phoenix24


2 Answers

From a Windows command line you can use:

echo %ERRORLEVEL%

For example:

C:\work>python helloworld.py
Hello World!

C:\work>echo %ERRORLEVEL%
0
like image 126
Dave Webb Avatar answered Oct 13 '22 01:10

Dave Webb


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
like image 39
Tarnschaf Avatar answered Oct 12 '22 23:10

Tarnschaf