By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,096 Members | 1,568 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,096 IT Pros & Developers. It's quick & easy.

named pipe input

P: n/a
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
Sep 1 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
max(01)* wrote:
$ cat file_input_3.py
#!/usr/bin/python

import sys

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

for riga in MIAPIPE:
print riga,
...
[...]
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.


You could try:

for riga in MIAPIPE:
print riga # NO COMMA!
sys.stdout.flush()

Sep 1 '05 #2

P: n/a
Eric Nieuwland wrote:
max(01)* wrote:
$ cat file_input_3.py
#!/usr/bin/python

import sys

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

for riga in MIAPIPE:
print riga,
...
[...]
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.

You could try:

for riga in MIAPIPE:
print riga # NO COMMA!
sys.stdout.flush()


doesn't work! :-(
Sep 1 '05 #3

P: n/a
In article <3g******************@news3.tin.it>,
"max(01)*" <ma**@fisso.casa> wrote:
i have some problems understanding following behaviour.

consider this: $ cat file_input_3.pl
#!/usr/bin/perl

open MIAPIPE, "una_pipe";

while ($riga = <MIAPIPE>) ....
$ cat file_input_3.py
#!/usr/bin/python

import sys

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

for riga in MIAPIPE:
.... 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.

Seems to me something like this came up here
not long ago. It turns out that

for line in file:

doesn't do the same thing as Perl's

while ($line = <file>)

If you use file.readline() instead (in a loop,
of course, I think you'll get the data one line
at a time, but "in file" apparently reads the
whole file first. That's what I vaguely remember,
I don't use it myself.

Donn Cave, do**@u.washington.edu
Sep 1 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.