这里是python2.4.x。在
我一直在努力让子进程和glob一起工作。在
好吧,这就是问题所在。在
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()
我在屏幕上收到许多“grep:writing output:breaked pipe”错误。在
一定是我错过了一些简单的东西,我就是找不到。有什么想法吗?在
提前谢谢你。在
这里的问题是,对于}。在
p2
,参数列表应该是['wc', '-l']
,而不是{目前,它正在寻找名为}连接的任何内容,这将导致断管错误。在
'wc -l'
的可执行文件来运行,但没有找到它,因此p2
立即失败,并且没有与{请尝试以下代码:
这似乎是因为在grep完成输出之前,
p1.stdout
正在关闭。也许你是想关闭pt.stdin
?但是似乎没有任何理由关闭这两个语句,所以我只删除p1.stdout.close()
语句。在相关问题 更多 >
编程相关推荐