由蟒蛇在shell脚本返回处理退出code [英] Handling exit code returned by python in shell script
本文介绍了由蟒蛇在shell脚本返回处理退出code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是从一个shell脚本中调用一个python脚本。 Python脚本返回失败的情况下,错误codeS。
I am calling a python script from within a shell script. The python script returns error codes in case of failures.
如何在shell脚本处理这些错误codeS并在必要时退出呢?
How do I handle these error codes in shell script and exit it when necessary?
推荐答案
最后一个命令的退出code被包含在 $?
。
The exit code of last command is contained in $?
.
下面的伪code用途:
Use below pseudo code:
python myPythonScript.py
ret=$?
if [ $ret -ne 0 ]; then
#Handle failure
#exit if required
fi
这篇关于由蟒蛇在shell脚本返回处理退出code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文