jeesezhang

1.在shell脚本执行python脚本时,需要通过python脚本的返回值来判断后面程序要执行的命令

例:有两个py程序  hello.py

def main():
    print "Hello"

if __name__==\'__main__\':
    main()

world.py

def main():
    print "Hello"

if __name__==\'__main__\':
    main()

shell 脚本 test.sh

python hello.py
python world.py

执行sh test.sh 打印结果为

  hello
  world

在hello.py中通过返回值  让shell脚本通过参数来判断,

hello.py这样写

import sys

def main():
    try:
        print "hello"
        sys.exit(0)
    except:
        sys.exit(1)

if __name__==\'__main__\':
    main()

shell 脚本改为

python hello.py
if [ $?==0 ];then
    exit
else
        python world.py        
fi

就可以判断了

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2021-12-04
  • 2021-12-10
  • 2021-10-10
  • 2021-08-30
猜你喜欢
  • 2021-08-19
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
  • 2018-08-18
  • 2021-07-21
相关资源
相似解决方案