当前位置:   article > 正文

Python fabric 1.4 解决run() received nonzero return code 2 while executing出错后脚本不能继续执行故障_python non-zero return code

python non-zero return code

默认情况下fabric配置参数warn_only=False,即run指令得到的程序结束返回值不为0则引发异常,退出后续的部署。

参考一下代码,有两种方式设置warn_only=True,可实现出错后能继续向下执行

  1. def deploy():
  2. with settings(
  3. warn_only=True
  4. ):
  5. run("ls /zz| grep ccc| grep -v fdsfds")
  6. print "111"
  7. run("ls /zz", warn_only=True)
  8. print "222"

输出参考

  1. D:\code\devops\trunk>fab -f test.py deploy
  2. [] Executing task 'deploy'
  3. [127.0.0.1:22] run: ls /zz| grep ccc| grep -v fdsfds
  4. [127.0.0.1:22] out: ls: cannot access /zz: No such file or directory
  5. [127.0.0.1:22] out:
  6. Warning: run() received nonzero return code 1 while executing 'ls /zz| grep ccc| grep -v fdsfds'!
  7. 111
  8. [127.0.0.1:22] run: ls /zz
  9. [127.0.0.1:22] out: ls: cannot access /zz: No such file or directory
  10. [127.0.0.1:22] out:
  11. Warning: run() received nonzero return code 2 while executing 'ls /zz'!
  12. 222
  13. Done.
  14. Disconnecting from 127.0.0.1:22... done.

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/985219
推荐阅读
相关标签
  

闽ICP备14008679号