简体   繁体   English

管道进入subprocess.call

[英]Piping into a subprocess.call

What I want to do is something very similar to the accepted answer in this question , however with a slight change. 我想要做的是与这个问题中接受的答案非常相似的东西,但稍有变化。 The last line: 最后一行:

print p3.communicate()[0]

prints the output of p3 . 打印p3的输出。 I would like to basically get subprocess.call() -like behaviour there instead of simply receiving the output at stdout. 我想基本上得到subprocess.call()类似的行为,而不是简单地在stdout接收输出。

For example, if p3 was less, using communicate , a pipe to less would behave more like a pipe to cat in that it wouldn't actually open less, but just print out the output. 例如,如果p3较少,使用communicate ,较少的管道将更像是管道,因为它实际上不会打开更少,但只打印出输出。

Is there anyway to achieve what I'm after (which is actually opening less rather than just it behaving like cat and communicating its output)? 反正有没有实现我所追求的目标(实际上是开放的更少而不仅仅是像猫一样表现并传达其输出)? A nod in the right direction would be fantastic. 向正确方向点头会很棒。

So instead of doing: 所以不要这样做:

p3 = Popen(cmd, stdin=p2.stdout, stdout=PIPE)
...
print p3.communicate()[0]

I can just do: 我可以这样做:

subprocess.call(cmd, stdin=p2.stdout)

And that will allow me to do what I wanted. 这将使我能够做我想做的事。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM