Can I catch error codes when using Fabric to run() calls in a remote shell?

前端 未结 4 641
花落未央
花落未央 2020-12-23 13:17

Normally Fabric quits as soon as a run() call returns a non-zero exit code. For some calls, however, this is expected. For example, PNGOut returns an error code of 2 when it

4条回答
  •  旧巷少年郎
    2020-12-23 13:50

    Apparently messing with the environment is the answer.

    fabric.api.settings can be used as a context manager (with with) to apply it to individual statements. The return value of run(), local() and sudo() calls isn't just the output of the shell command, but also has special properties (return_code and failed) that allow reacting to the errors.

    I guess I was looking for something closer to the behaviour of subprocess.Popen or Python's usual exception handling.

提交回复
热议问题