调用Python从蝙蝠文件,获取收益code [英] Call Python From Bat File And Get Return Code
问题描述
我正在寻找一种方式来从一个批处理文件调用一个python脚本,并充分利用Python脚本返回code。混淆我知道,但它是基于一个系统,是目前使用的。我会重新写,但是,这个方法是多,快多了。
所以:
蝙蝠--------------------->蟒蛇
*调用Python文件*蝙蝠< ---------------------------------的Python
* Python做的工作负载*
*和返回一个返回code *
Windows外壳程序保存在 ERRORLEVEL
变量返回code:
蟒蛇somescript.py
回声%ERRORLEVEL%
在Python脚本就可以退出脚本,并通过调用设置返回值退出()
:
出口(15)
在旧版本的Python,你可能首先必须导入退出()
从 SYS
模块功能:
从SYS进口出口
出口(15)
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 *
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)
这篇关于调用Python从蝙蝠文件,获取收益code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!