[Tutor] Popen problem with a pipe sign "|"

Sander Sweers sander.sweers at gmail.com
Sat Jul 4 00:40:42 CEST 2009


2009/7/3 hyou <hyou00 at hotmail.com>:
> Hi Sander,
>
> Thanks for the reply. However, the reason that I have to use subprocess.call is that if I use
> subprocess.Popen, the pipe sign "|" will break the execution of the command (though I don't know
> why). Do you know how can I put "|" correctly in Popen then? (The same command works fine both in
> Command prompt and subprocess.call, but not .Popen)

You create a Popen object for each program and redirect the stdout
from program 1 to subprocess.PIPE. Now in program 2 you read the
stdout from command 1 to the stdin. See below a simple example.

p1 = subprocess.Popen('command1', stdout = subprocess.PIPE)
p2 = subprovess.Popen('command2', stdin = p1.stdout)

Greets
Sander

PS: Please make sure you also reply to the list.


More information about the Tutor mailing list