Connecting Tech Pros Worldwide Forums | Help | Site Map

reading from stdin via pipe, buffering?

Rudy Gevaert
Guest
 
Posts: n/a
#1: Feb 29 '08
Hi,

I have written an perl program that read from stdin:
while(<STDIN>)
{
chomp
do_it($_);
}
Data is fed to it via a pipe:

cat myfile | ./myprogram

When running the program, the program doesn't always read the whole
line. I'm guessing this has something to do with the stdin buffer.

I would like to know how I can make that perl gets the whole line. As
it is clearly failing from time to time.

Thanks in advance,

Rudy



Rodrick Brown
Guest
 
Posts: n/a
#2: Mar 9 '08

re: reading from stdin via pipe, buffering?



"Rudy Gevaert" <Rudy.Gevaertno@ugentspam.bewrote in message
news:fq942i$357$1@gaudi2.UGent.be...
Quote:
Hi,
>
I have written an perl program that read from stdin:
while(<STDIN>)
{
chomp
do_it($_);
}
Data is fed to it via a pipe:
>
cat myfile | ./myprogram
>
When running the program, the program doesn't always read the whole line.
I'm guessing this has something to do with the stdin buffer.
>
I would like to know how I can make that perl gets the whole line. As it
is clearly failing from time to time.
>
Thanks in advance,
>
Rudy
>
>
Try disabling buffering $|++;

Joe Smith
Guest
 
Posts: n/a
#3: Mar 15 '08

re: reading from stdin via pipe, buffering?


Rodrick Brown wrote:
Quote:
>
"Rudy Gevaert" <Rudy.Gevaertno@ugentspam.bewrote in message
news:fq942i$357$1@gaudi2.UGent.be...
Quote:
>When running the program, the program doesn't always read the whole
>line. I'm guessing this has something to do with the stdin buffer.
>>
>
Try disabling buffering $|++;
Won't help. $| controls output buffering; it has no affect on STDIN.
Closed Thread