Output to file is not flushing immediately

Discussion in 'Perl Misc' started by void.no.spam.com@gmail.com, Mar 25, 2008.

  1. Guest

    I have a perl script that writes stuff to a text file. While the
    script is running, I do a "tail -f" on the text file to see the
    output. But I can tell that the output isn't being flushed
    immediately, because the script writes something to the file
    immediately before sleeping for 60 seconds, but I don't see that
    output show up in the "tail -f" until after it comes back from
    sleeping.

    I thought that putting a "\n" at the end of a print would do a flush,
    but that's obviously not the case.

    I also read that if you put "$| = 1" at the beginning of your script,
    then it would do a flush after every print or write command. I tried
    that, and it still does not flush.
    , Mar 25, 2008
    #1
    1. Advertising

  2. Guest

    "" <> wrote:
    > I have a perl script that writes stuff to a text file. While the
    > script is running, I do a "tail -f" on the text file to see the
    > output. But I can tell that the output isn't being flushed
    > immediately, because the script writes something to the file
    > immediately before sleeping for 60 seconds, but I don't see that
    > output show up in the "tail -f" until after it comes back from
    > sleeping.
    >
    > I thought that putting a "\n" at the end of a print would do a flush,
    > but that's obviously not the case.


    use IO::Handle;
    #...
    $fh->autoflush();

    >
    > I also read that if you put "$| = 1" at the beginning of your script,
    > then it would do a flush after every print or write command. I tried
    > that, and it still does not flush.


    That will only turn autoflush on for the STDOUT (or whatever the currently
    selected filed handle is).

    Read all about it here:
    perldoc -q flush

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    The costs of publication of this article were defrayed in part by the
    payment of page charges. This article must therefore be hereby marked
    advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    this fact.
    , Mar 25, 2008
    #2
    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. Hikikomori
    Replies:
    4
    Views:
    6,356
    Thomas 'Skip' Hollowell
    Mar 24, 2005
  2. Christopher Benson-Manica

    streambuf not flushing, apparently

    Christopher Benson-Manica, Feb 26, 2004, in forum: C++
    Replies:
    5
    Views:
    563
    John Harrison
    Feb 26, 2004
  3. Aryk Grosz
    Replies:
    4
    Views:
    250
    Aryk Grosz
    Oct 10, 2008
  4. J
    Replies:
    0
    Views:
    155
  5. Cameron Simpson

    Re: Flushing buffer on file copy on linux

    Cameron Simpson, Aug 15, 2012, in forum: Python
    Replies:
    0
    Views:
    164
    Cameron Simpson
    Aug 15, 2012
Loading...

Share This Page