Having trouble converting popen2 to subprocess

Daniel Klein danielkleinad at gmail.com
Sat Nov 18 14:52:21 CET 2006

Here's a c routine that prints a single line :

#include <stdio.h>
  printf ("Hello World!\n");

And now the Python program (called 'po.py') that uses 'popen2' :

import popen2
(fin, fout) = popen2.popen2(r'c:\home\hw.exe', -1, 't')
print fin.readline()

When this is run it properly outputs the one line from the c routine :

C:\>python c:\python\po.py
Hello World!

Now here is my attempt to use the 'subprocess' module :

from subprocess import *
p = Popen(r'c:\home\hw.exe', bufsize=-1, stdin=PIPE, stdout=PIPE,
fin = p.stdin
print fin.readline()

When this is run, I get no output :

C:\>python c:\python\sp.py


As you can see, I get no exception.

I've tried various combinations of the Popen arguments with no joy.

The platform is Windows XP Pro, so I did not try things like

What am I missing ?

Daniel Klein

More information about the Python-list mailing list