[Tutor] (no subject)(About Pipe)
orion_val at 163.com
Thu Dec 30 04:28:33 CET 2004
I've read your code. May the main problem locates at "cmd". Assume
that foo.py and listen.py are at the same directory. It should look like:
or if you included '#!/usr/bin/python' (Linux) or
'#!/usr/local/bin/python' (FreeBSD) as the first line in listen.py and
you changed mode of listen.py to a+x
or even if you are now in some one of PATH
Maybe it hits the point. Just maybe, because you didn't give your output.
Here is an example code, it really works at least.
pin.write('Here is a message from pipe.')
uh=raw_input("Write this through pipe: ")
#Write this to stdin, so uh should have message
print 'No message.'
>I am trying to supply input to another program using
>pipes. I can read from it just fine, but writing to
>its stdin doesn't seem to be working.
>foo.py (gets pipe to listen.py)
>from popen2 import popen2
>cmd = "listen.py"
>r, w = popen2(cmd)
>got = r.readlines()
>for line in got:
> print line
># wrote to this stdin, so uh should have message
>uh = raw_input("why doesn't it")
>if "" != uh:
> print "go here?"
>if "" == uh:
> print "or even here?"
>I know I'm missing something conceptual...
>I only get "why doesn't it" printed to the screen and
>the message didn't seem to transfer across the pipe,
>as listen.py aborted before the if statement somehow.
>Any and all help would be appreciated; popen2._test()
>works fine ...
>Do You Yahoo!?
>Tired of spam? Yahoo! Mail has the best spam protection around
>Tutor maillist - Tutor at python.org
More information about the Tutor