I'm looking for a way to call a python script from a batch file and getting a return code from the python script. Confusing I know, but it's based on a system that's currently in use. I'd re-write it, but this way would be much, much quicker.
So:
Bat ---------------------> Python
* call python file *
Bat <--------------------------------- Python
* python does a load of work *
* and returns a return code *
Syntax. It is common to use the command EXIT /B %ERRORLEVEL% at the end of the batch file to return the error codes from the batch file. EXIT /B at the end of the batch file will stop execution of a batch file. Use EXIT /B < exitcodes > at the end of the batch file to return custom return codes.
To display the 0 or 1 return code values, you must type the pdadmin command, followed by either the AIX®, Linux®, or Solaris echo or the Windows errorlevel command: For AIX, Linux, and Solaris operating systems: # pdadmin_command # echo $?
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)
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