update file in real time via CGI script

R

Ravi Parimi

Hi,
I have a process that is writing to a file and it takes about 5
minutes before the writing is done.

I would like to view the file as it is being updated via a cgi script.

I tried using a pipe as:

open F,"tail -f -n 1000 my_file" or die "$!";

while(<F>) {
print;
}

This program works fine when I run it from the command line. However when
I run it as a CGI script(with all headers in place), I cannot see
any output, and the browser freezes...

The "-n 1000" args for tail are just to make sure I get all the lines from
the file. Any help is greatly appreciated.


Many thanks,
--ravi
 
W

Walter Roberson

: I have a process that is writing to a file and it takes about 5
:minutes before the writing is done.

:I would like to view the file as it is being updated via a cgi script.

:I tried using a pipe as:

:eek:pen F,"tail -f -n 1000 my_file" or die "$!";

You are missing the leading pipe symbol indicating that you are reading
from a different process.

:while(<F>) {
: print;
:}

:This program works fine when I run it from the command line. However when
:I run it as a CGI script(with all headers in place), I cannot see
:any output, and the browser freezes...

Unless you emitted a <PRE> tag ahead of this, your browser is
waiting for the single long section to finish in order to render it
as HTML. Recall that normally newlines are just whitespace in HTML.

If you want to see the output as it is being generated, you need to
use one of the HTML mechanisms to push out further output. That can
be by periodically closing the HTML and using a meta refresh (in which
case your CGI has to keep track of what to send this time). Another
possibility is to use a chain of 'multipart' content types, with each
new part reflecting additional output. But that's an HTML trick,
not a perl trick. Check around for information on html push technology.
 
J

Joe Smith

Ravi said:
open F,"tail -f -n 1000 my_file" or die "$!";

You've left out a character.

open F,"tail -f -n 1000 my_file|" or die "tail of my_file: $!";

You can avoid using an external program if you
use File::Tail;
-Joe
 

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,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top