Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > reading from stdin via pipe, buffering?

Reply
Thread Tools

reading from stdin via pipe, buffering?

 
 
Rudy Gevaert
Guest
Posts: n/a
 
      02-29-2008
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


 
Reply With Quote
 
 
 
 
Rodrick Brown
Guest
Posts: n/a
 
      03-09-2008

"Rudy Gevaert" <(E-Mail Removed)> wrote in message
news:fq942i$357$(E-Mail Removed)...
> 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 $|++;

 
Reply With Quote
 
 
 
 
Joe Smith
Guest
Posts: n/a
 
      03-15-2008
Rodrick Brown wrote:
>
> "Rudy Gevaert" <(E-Mail Removed)> wrote in message
> news:fq942i$357$(E-Mail Removed)...
>> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
peek at stdin, flush stdin Johnathan Doe C Programming 5 05-17-2013 04:30 PM
reading from stdin via pipe, buffering? Rudy Gevaert Perl Misc 4 03-04-2008 07:47 AM
Reading from stdin then launching a program that reads from stdin strange behaviour Stefano Sabatini Perl Misc 6 07-29-2007 10:38 PM
Detect if stdin is via keyboard or via < file? srbstar@sbcglobal.net C Programming 3 08-31-2005 11:20 AM
Reading stdin once confuses second stdin read Charlie Zender C Programming 6 06-21-2004 01:39 PM



Advertisments