Click here to get back home

Output to file is not flushing immediately

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Output to file is not flushing immediately void.no.spam.com@gmail.com 03-25-2008
Posted by void.no.spam.com@gmail.com on March 25, 2008, 4:19 pm
Please log in for more thread options
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.

Posted by xhoster on March 25, 2008, 4:38 pm
Please log in for more thread options
> 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.

Similar ThreadsPosted
IO::Select->can_read returns immediately January 27, 2006, 10:37 am
How can I send the output of the system() command to a file and capture a string in that file June 19, 2005, 1:30 pm
Kindly help :::How can I send the output of the system() command to a file and capture a string in one of the lines in that file June 19, 2005, 1:40 pm
Writng console output to a file June 17, 2005, 4:19 am
Is it possible to open a file for both input & output April 27, 2006, 8:14 am
Is it possible to open aa file for both input & output April 27, 2006, 8:41 am
Open local file for output December 20, 2006, 11:46 pm
sending output to STDOUT or a file April 22, 2008, 2:26 pm
Running Java file and capturing output February 21, 2007, 3:06 pm
UTF16 input file to ISO-8859-1 output April 16, 2007, 9:56 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap