shell脚本中执行python脚本并接收其返回值的例子
2014-08-29 00:00
901 查看
1.在shell脚本执行python脚本时,需要通过python脚本的返回值来判断后面程序要执行的命令
例:有两个py程序 hello.py
shell 脚本 test.sh
执行sh test.sh 打印结果为
在hello.py中通过返回值 让shell脚本通过参数来判断,
hello.py这样写
shell 脚本改为
就可以判断了
例:有两个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
就可以判断了
相关文章推荐
- shell脚本中执行python脚本并接收其返回值的例子
- shell脚本中执行python脚本并接收其返回值的例子
- shell脚本执行python脚本时,python如何将返回值传给shell脚本
- python调用其它脚本:pig,python,shell等等 (如何获取pig脚本执行的返回值)
- python调用其它脚本:pig,python,shell等等 (如何获取pig脚本执行的返回值)
- [Python陷阱]os.system调用shell脚本获取返回值
- Python执行Shell命令测试脚本
- python执行shell脚本
- shell脚本接收存储过程返回值
- python 执行shell命令无法获取返回值的解决方法
- python2.7执行shell脚本
- Python自动化测试例子--一个简单的自动化测试用例脚本--批量执行测试用例
- Python执行shell脚本
- Python执行shell脚本的几种方式(最好用subprocess.Popen来替代os.system)
- 利用python执行shell脚本 并动态传参 及subprocess基本使用
- python ,shell 脚本 执行同样操作,花费时间效率对比
- Python脚本中执行shell命令
- shell脚本中接收返回值
- python脚本批量执行shell,使用queue、threading库
- python脚本执行shell命令或脚本