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