fabric 当执行返回码出现非0的命令时, 直接抛出异常退出的。
这种异常不是Exception异常, 而是一个SystemExit异常。
如果需要捕捉异常处理, 只需要
:::python
try:
fab_execute(publish_ccms_pd_root, host=self.host, info=self.info, functions=self.functions)
except SystemExit:
self.write_error()
或者
:::python
try:
run('''ls -al ''')
except SystemExit:
event()
但不建议这样做, 如果你仅仅是碰到错误还是要继续执行, 而不做异常的操作。
可以使用官方的settins.warn_only = True, 这样的话碰到不正常返回码仅仅会抛出Warning 信息。
第一种:
环境变量
:::python
from fabric.state import env
env.warn_only = True
第二种:
settings
:::python
from fabric.api import settings
with settings(warn_only=True):
run('ls -al')
版权声明:自由转载-非商用-非衍生-保持署名 | Creative Commons BY-NC-ND 3.0