擅长:python、mysql、java
<p>也许将<code>grep</code>传递给<code>communicate()</code>-函数并不像您假设的那样工作。可以通过直接从文件中重新映射来简化过程,如下所示:</p>
<pre><code>In [14]: a = subprocess.Popen(['grep "#pyName" test.txt'], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr=subprocess.PIPE, shell = True)
In [15]: a.communicate()
Out[15]: ('#pyName: test.txt\n', '')
</code></pre>
<p>用python做你想做的事情可能会更聪明。如果您的行在文件中,下面将打印它。在</p>
^{pr2}$