named pipe input

max(01)* max2 at fisso.casa
Thu Sep 1 21:03:27 CEST 2005


hi there.

i have some problems understanding following behaviour.

consider this:

...
$ cat file_input_3.pl
#!/usr/bin/perl

open MIAPIPE, "una_pipe";

while ($riga = <MIAPIPE>)
   {
     print STDOUT ("$riga");
   }

$ cat file_input_3.py
#!/usr/bin/python

import sys

MIAPIPE = open("una_pipe", "r")

for riga in MIAPIPE:
   print riga,
...

where una_pipe is a named pipe (created with mkfifo).

when i run this on console #1:

...
$ ./file_input_3.pl
...

and this un console #2:

...
$ cat > una_pipe
aaa
bbb
ccc
...

then each line typed in console #2 appears on console #1 as soon as the 
line is terminated (hit return).

BUT if i try to do the same with the python code, something different 
happens: i have to type ALL the lines on console #2 and complete the cat 
command (ctrl-d) before seeing the lines echoed on console #1.

i tried the -u flag but doesnt seem to work.

any help?

bye



More information about the Python-list mailing list