0

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. I would like to basically get subprocess.call()-like behaviour there instead of simply receiving the output at 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.

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.

Community
  • 1
  • 1
hfaran
  • 524
  • 1
  • 4
  • 18
  • Could you describe *what* do you want to do using words (without the code)? Then what have you tried e.g., replacing the last `Popen(stdout=PIPE)/communicate()` with a `call(stdout=None)` and how that failed (a minimal complete code example that shows the problem would be helpful)? – jfs May 11 '13 at 07:15
  • I was being rather dumb and completely did not read the documentation; I'll post my answer below. – hfaran May 11 '13 at 07:22

1 Answers1

2

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. :)

hfaran
  • 524
  • 1
  • 4
  • 18