Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Output to file is not flushing immediately

Reply
Thread Tools

Output to file is not flushing immediately

 
 
void.no.spam.com@gmail.com
Guest
Posts: n/a
 
      03-25-2008
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.
 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      03-25-2008
"(E-Mail Removed)" <(E-Mail Removed)> 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.
 
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
Re: Flushing buffer on file copy on linux Cameron Simpson Python 0 08-15-2012 03:09 AM
Flushing buffer on file copy on linux J Python 0 08-15-2012 02:55 AM
"print" not showing immediately in output, but "puts" is Aryk Grosz Ruby 4 10-10-2008 09:01 AM
Struts: findForward after flushing output stream. Hikikomori Java 4 03-24-2005 03:38 PM
Flushing data on file system (?) English Patient Computer Support 6 11-28-2004 08:40 PM



Advertisments