擅长:python、mysql、java
<p>当传递shell=True时,python将命令转换为<code>/bin/sh -c <command></code>(如<a href="http://docs.python.org/library/subprocess.html#popen-constuctor" rel="nofollow">here</a>)所述。/bin/sh显然不支持大括号扩展。您可以尝试以下方法:</p>
<pre><code>import subprocess
subprocess.Popen(["/bin/bash", "-c", "egrep -r --exclude=*{.git,.svn}* \"text\" ~/directory"], stdout=subprocess.PIPE).communicate()[0]
</code></pre>