named pipe question
Christopher T King
squirrel at WPI.EDU
Tue Jul 13 19:44:12 CEST 2004
On Tue, 13 Jul 2004, Rajarshi Guha wrote:
> fin = open('/tmp/mypipe','r+')
> (I don't use 'r' as that cause the open command to block).
It only blocks until a process connects to it for writing. 'r+' causes it
not to block because it causes 'fin' to be connected for both reading and
writing (probably not what you want). You should use 'r' as the mode.
> ls -l /tmp/mypipe
You probably mean 'ls -l > /tmp/mypipe'. The command you have just lists
/tmp/mypipe; you need the redirection symbol to send the output to
/tmp/mypipe, otherwise it just ends up on the screen.
> and then from my Python session do:
> it just hangs and I have to Ctrl-C to get out.
This command will block until the writing process has closed the pipe.
Because you opened fin for both reading and writing, this command will
never return (it's basically waiting for itself to close).
> But when I do from a terminal:
> ls -l /tmp/mypipe ; cat < /tm/mypipe
> I get the output of the ls command.
As above, this should be ls -l > /tmp/mypipe to work properly. This just
lists /tmp/mypipe directly to the screen. (It should probably block, too.)
Hope this helps.
More information about the Python-list