擅长:python、mysql、java
<p>Grep在许多不同的情况下返回非零退出代码。从手册页:</p>
<blockquote>
<p>EXIT STATUS
The grep utility exits with one of the following values:</p>
<pre><code> 0 One or more lines were selected.
1 No lines were selected.
>1 An error occurred.
</code></pre>
</blockquote>
<p>所以这里有一个不匹配的退出代码。只需使用上下文管理器并将节设置为<code>warn_only</code>:</p>
<pre><code>from fabric.api import settings, run
def test(path):
with settings(warn_only=True):
return run('grep ...')
</code></pre>
<p>参考号:</p>
<ul>
<li><a href="http://docs.fabfile.org/en/1.10/usage/env.html#the-settings-context-manager" rel="nofollow">http://docs.fabfile.org/en/1.10/usage/env.html#the-settings-context-manager</a></li>
</ul>