擅长:python、mysql、java
<p>这里的问题是,对于<code>p2</code>,参数列表应该是<code>['wc', '-l']</code>,而不是{<cd3>}。在</p>
<p>目前,它正在寻找名为<code>'wc -l'</code>的可执行文件来运行,但没有找到它,因此<code>p2</code>立即失败,并且没有与{<cd6>}连接的任何内容,这将导致断管错误。在</p>
<p>请尝试以下代码:</p>
<pre><code>def runCommands(thecust, thedevice):
thepath='/smithy/%s/%s' % (thecust,thedevice)
thefiles=glob.glob(thepath + '/*.smithy.xml')
p1=subprocess.Popen(["grep", "<record>"] + thefiles, stdout=subprocess.PIPE)
p2=subprocess.Popen(['wc', '-l'], stdin=p1.stdout, stdout=subprocess.PIPE)
p1.stdout.close()
thecount=p2.communicate()[0]
p1.wait()
</code></pre>