Popen一个命令,其中包含对所有输出都需要说“是"的命令 [英] Popen a command that contains need to say yes for all outputs
本文介绍了Popen一个命令,其中包含对所有输出都需要说“是"的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要自动执行以下命令
I need to automate the following command
cmd="yes | vgremove <vgname>"
每当我使用此代码编写
Popen(cmd.split(),stdout=PIPE,stderr=PIPE)
它没有完成.我怀疑它会等到命令完成后,才敲打管道,这是否有替代方法?
it does not complete. I suspect it waits till the command gets complete, so the pipe is struck, is there an alternative for this???
推荐答案
在这种情况下,有一种更简单的方法:
There is a much easier way in this case:
Popen('vgremove -f <vgname>')
对于您的问题,具体来说:
As for your question specifically:
p = Popen(cmd.split(), stdout=PIPE, stderr=PIPE, stdin=PIPE)
p.stdin.write('yes')
这篇关于Popen一个命令,其中包含对所有输出都需要说“是"的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文