Home > Archive > PERL Miscellaneous > March 2008 > Output to file is not flushing immediately
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Output to file is not flushing immediately
|
|
| void.no.spam.com@gmail.com 2008-03-25, 7:19 pm |
| 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.
| |
| xhoster@gmail.com 2008-03-25, 7:19 pm |
| "void.no.spam.com@gmail.com" <void.no.spam.com@gmail.com> 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.
|
|
|
|
|