Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
批处理文件未从其启动的python脚本接收ERRORLEVEL_Python_Batch File_Errorlevel - Fatal编程技术网

批处理文件未从其启动的python脚本接收ERRORLEVEL

批处理文件未从其启动的python脚本接收ERRORLEVEL,python,batch-file,errorlevel,Python,Batch File,Errorlevel,我有一个运行python脚本的批处理文件。 此python脚本始终以sys.exit(code)结束,不管发生什么,代码都是错误代码。 批处理文件不获取我的错误代码,而是始终读取0,并显示以下内容: ..\..\STS\Python\python.exe Version_code_ID.py %* echo Error level = %ERRORLEVEL% python的这一版本在3.7.1中。 我确信我的python代码与0以外的其他代码一起退出,这要归功于我的记录器(我出于测试目的

我有一个运行python脚本的批处理文件。
此python脚本始终以
sys.exit(code)
结束,不管发生什么,代码都是错误代码。
批处理文件不获取我的错误代码,而是始终读取0,并显示以下内容:

..\..\STS\Python\python.exe Version_code_ID.py %*  
echo Error level = %ERRORLEVEL%
python的这一版本在3.7.1中。
我确信我的python代码与0以外的其他代码一起退出,这要归功于我的记录器(我出于测试目的自愿导致错误)。
例如,我让它以1和12退出,这两次尝试都会在批处理中得到0

以防万一,这里还有我用来退出的python函数:

def exit(code):
    if(code > 0 ):
        log.error("The computing module will shutdown with the following error code : "+str(code))
    elif(code == 0):
        log.info("Execution sucessfull")
    log.info("STOP of VERSION_CODE_ID Computing Module")
    log.removeHandler(stream_handler)
    log.removeHandler(file_handler)
    stream_handler.close()
    file_handler.close()
    sys.exit(code)
log只是我的logging.logger的名称


知道是什么导致了这个问题吗?

原来问题是我的python脚本的大部分都在这个try子句中:

try:
    #All of my code
except SystemExit:
    ()
except Exception as ex:
    fun.log.error('ERROR: Unknown exception: ' + repr(ex))  
我最初添加了

except SystemExit:
    () 
因为我认为SystemExit在控制台中显示为“异常”是个问题,但事实并非如此。
简言之,解决方案是除去
之外的

原因似乎是,顾名思义,捕获
systemExit
,不会让它被发送到批处理,而批处理认为没有发送错误代码


令人惊讶的是,除了异常,例如:
没有捕获由
sys.exit()
生成的
systemExit
。这在我的情况下非常好,因为我仍然需要它来记录未知的异常。

我不会调用函数
exit
,因为有一个内置函数已经有了这个名称。。。