Call Python From Bat File And Get Return Code

[From]: http://stackoverflow.com/questions/1013246/call-python-from-bat-file-and-get-return-code

The windows shell saves the return code in the ERRORLEVEL variable:

python somescript.py
echo %ERRORLEVEL%

In the python script you can exit the script and set the return value by calling exit():

exit(15)

In older versions of python you might first have to import the exit() function from the sys module:

from sys import exit
exit(15)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s