reading from stdin via pipe, buffering?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rudy Gevaert

    reading from stdin via pipe, buffering?

    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

    #2
    Re: reading from stdin via pipe, buffering?


    "Rudy Gevaert" <Rudy.Gevaertno @ugentspam.bewr ote in message
    news:fq942i$357 $1@gaudi2.UGent .be...
    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 $|++;

    Comment

    • Joe Smith

      #3
      Re: reading from stdin via pipe, buffering?

      Rodrick Brown wrote:
      >
      "Rudy Gevaert" <Rudy.Gevaertno @ugentspam.bewr ote in message
      news:fq942i$357 $1@gaudi2.UGent .be...
      >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.

      Comment

      Working...