如果Fabric在执行local()
命令时遇到错误代码,则会抛出异常,如:
Fatal error: local() encountered an error (return code 127) while executing '...'
但是,它实际上并不显示命令中的任何stdout
或stderr
,即使您指定了capture=True
,这是非常无益的。 how to capture these上有解释,但由于Fabric会抛出异常,因此无法保存local()
的结果并对其进行内省。
如何在运行local()
时遇到错误时让Fabric显示有用的错误消息?
答案 0 :(得分:0)
在关闭的机会中,您仍然可以使用github中的工具来完成此任务; Gusset
如果您选择使用此选项,您的代码将如下所示:
from gusset.output import with_output
from fabric.api import local, task
@with_output(verbosity=2)
@task
def my_failing_task():
local("blahblah")
In [4]: my_failing_task()
[localhost] local: blahblah
/bin/sh: 1: blahblah: not found
Fatal error: local() encountered an error (return code 127) while executing 'blahakh'
None
Aborting.
An exception has occurred, use %tb to see the full traceback.
我也想象你可以从Gusset中取出code,然后将其粘贴到你自己的应用程序中