update file in real time via CGI script

Discussion in 'Perl Misc' started by Ravi Parimi, Jan 29, 2004.

  1. Ravi Parimi

    Ravi Parimi Guest

    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
    Ravi Parimi, Jan 29, 2004
    #1
    1. Advertising

  2. In article <>,
    Ravi Parimi <> wrote:
    : 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.
    --
    Aleph sub {Aleph sub null} little, Aleph sub {Aleph sub one} little,
    Aleph sub {Aleph sub two} little infinities...
    Walter Roberson, Jan 29, 2004
    #2
    1. Advertising

  3. Ravi Parimi

    Joe Smith Guest

    Ravi Parimi wrote:

    > 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
    --
    I love my TiVo - http://www.inwap.com/u/joe/tivo/
    Joe Smith, Feb 1, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex
    Replies:
    5
    Views:
    917
  2. ReTrY

    Real-time Update

    ReTrY, Jul 18, 2007, in forum: Python
    Replies:
    6
    Views:
    451
    Hendrik van Rooyen
    Jul 20, 2007
  3. Muzammil
    Replies:
    1
    Views:
    1,110
    red floyd
    Aug 28, 2008
  4. fatted
    Replies:
    1
    Views:
    128
    Steve Grazzini
    Jul 25, 2003
  5. kath
    Replies:
    4
    Views:
    574
    J. Gleixner
    Apr 9, 2007
Loading...

Share This Page