reading from stdin via pipe, buffering?

Discussion in 'Perl' started by Rudy Gevaert, Feb 29, 2008.

  1. Rudy Gevaert

    Rudy Gevaert Guest

    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
    Rudy Gevaert, Feb 29, 2008
    #1
    1. Advertising

  2. "Rudy Gevaert" <> wrote in message
    news:fq942i$357$...
    > 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 $|++;
    Rodrick Brown, Mar 9, 2008
    #2
    1. Advertising

  3. Rudy Gevaert

    Joe Smith Guest

    Rodrick Brown wrote:
    >
    > "Rudy Gevaert" <> wrote in message
    > news:fq942i$357$...
    >> 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.
    Joe Smith, Mar 15, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charlie Zender

    Reading stdin once confuses second stdin read

    Charlie Zender, Jun 19, 2004, in forum: C Programming
    Replies:
    6
    Views:
    770
    Dan Pop
    Jun 21, 2004
  2. Ara.T.Howard

    pipe buffering

    Ara.T.Howard, Oct 15, 2004, in forum: Ruby
    Replies:
    0
    Views:
    97
    Ara.T.Howard
    Oct 15, 2004
  3. Stefano Sabatini
    Replies:
    6
    Views:
    286
    Stefano Sabatini
    Jul 29, 2007
  4. Rudy Gevaert

    reading from stdin via pipe, buffering?

    Rudy Gevaert, Mar 3, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    220
    Rudy Gevaert
    Mar 4, 2008
  5. DaLoverhino

    Reading from pipe or from stdin, how?

    DaLoverhino, May 1, 2009, in forum: Perl Misc
    Replies:
    1
    Views:
    158
    Jim Gibson
    May 2, 2009
Loading...

Share This Page