junjie 通过本文主要向大家介绍了python调用shell脚本,python shell脚本,python 执行shell脚本,shell脚本返回值,shell脚本编程大全等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
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()
</div>
shell 脚本 test.sh
python hello.py
python world.py
</div>
执行sh test.sh 打印结果为
hello
world
</div>
在hello.py中通过返回值 让shell脚本通过参数来判断,
hello.py这样写
import sys
def main():
try:
print "hello"
sys.exit(0)
except:
sys.exit(1)
if __name__=='__main__':
main()
</div>
shell 脚本改为
python hello.py
if [ $?==0 ];then
exit
else
python world.py
fi
</div>
就可以判断了

