shell脚本中判断上一条python命令执行情况

shell脚本中判断python命令执行结果

python脚本main.py

import sys
def main():
    try:
        "执行相关操作"
        sys.exit(0)
    except Exception as e:
        print(e)
        sys.exit(1)
if __name__ == '__main__':
    main()

shell脚本

python main.py
if [ $? -eq 0 ];then
echo "python 代码执行成功。"
else
echo "python 代码执行出错。"
fi

猜你喜欢

转载自blog.csdn.net/kmlyc/article/details/80684966