unix pipes + python
Timothy Docker
timd at macquarie.com.au
Thu Dec 28 18:56:47 EST 2000
I must be doing something silly here...
| import os
|
| def child( infd ) :
| "Run a child process"
| pid = os.fork()
| if pid == 0:
| if infd != None: os.dup2( infd, 0 )
| os.execv( '/usr/bin/cat', ['cat'] )
| else:
| return pid
|
| toPipe,fromPipe = os.pipe()
| child( fromPipe )
| os.write( toPipe, "hello\nthere\n" )
| os.close( toPipe )
This script behavious almost as expected. I end up with the text
echoed back, but the 'cat' subprocess is left running - I was
expecting it to exit when the write side of the pipe was closed in the
parent, but it is still reading from fd 0.
Any suggestions on what's wrong?
Thanks,
Tim
More information about the Python-list
mailing list