Output to file is not flushing immediately

G

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.
 
X

xhoster

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top