Talking through pipes interactively (on win32)

Jane Austine janeaustine50 at hotmail.com
Mon Nov 10 10:16:43 EST 2003


> Can you please post a small script showing the exact problem you have? 
> Communicating with a program via pipes works on Windows: we do it all the 
> time.  It can be pretty complicated, but it can be done.

Okay. For example, python interactive shell:

>>> import os
>>> sout,sin=os.popen2('python -u')
>>> sout.write('print 2*3\n')
>>> sout.flush()
>>> sin.read(1)

...(it hangs from here)...

However, it works if sout is closed before reading from sin:
>>> import os
>>> sout,sin=os.popen2('python -u')
>>> sout.write('print 2*3\n')
>>> sout.close()
>>> sin.read(1)
'6'




More information about the Python-list mailing list