newbie: how to capture/write to stdio on NT

Arnold Filip afilip--usenet at freenet.de
Wed May 26 03:56:34 EDT 2004


Sholtz wrote:
> Hi,
> 
> I am trying to figure out how to 'control' the input & output using
> popen/popen2 etc on Python 2.3
> I have found examples for unix such as the one below but I can't get it to
> work on Windows NT.
> 
> If I use the os.popen module I can read OR write not both.
> 
> Anybody have any ideas?
> 
> Regards,
> 
> Sholto.
> 
> # Open command in a pipe
> # which reads from stdin and writes to stdout
> 
> import popen2
> pipe = popen2.Popen4("wc -l") # Unix command
> pipe.tochild.write("line 1\nline 2\nline 3\n")
> pipe.tochild.close()
> output = pipe.fromchild.read()
> 
> 

I use the process.py module for this purpose:
http://starship.python.net/crew/tmick/

Example (works on windows):

import process
import sys

p = process.ProcessProxy( sys.argv[1:],
                           stdout=sys.stderr,
                           stderr=sys.stderr )
p.wait()

Cheers
Arnold



More information about the Python-list mailing list