我想做一些简单的事情,例如检查文件中是否可以找到字符串,如果没有,则执行某些操作。 Fabric退出时出错。有什么解决方法吗?
result = local("grep %s /tmp/file" % env.hosts[0])
if result.failed:
print "shit failed"
else:
print "was already added, noop!"
输出
# fab -H 1.2.3.5
[localhost] local: grep 1.2.3.5 /etc/bitrate/puppetmaster/firewall
Fatal error: local() encountered an error (return code 1) while executing 'grep 1.2.3.5 /etc/bitrate/puppetmaster/firewall'
Aborting.
答案 0 :(得分:0)
这样做的一种方法是'with quiet():'
with quiet():
result = local("something")
if result.failed:
....
else:
....