in reply to Long Process Waits Until End to Display Results

http://www.stonehenge.com/merlyn/LinuxMag/col39.html gives one approach that you can use.
  • Comment on Re: Long Process Waits Until End to Display Results

Replies are listed 'Best First'.
Re^2: Long Process Waits Until End to Display Results
by C_T (Scribe) on Dec 07, 2004 at 17:33 UTC
    Someone sent me that excellent article in response to another question. The problem is not the browser timing out, but rather that the process waits until the end to display the results.

    I've actually used the exact code that's in the article you reference:

    my $command = "make -i -j 10 -f upgrade.make"; unless (open F, "-|") { open STDERR, ">&=1"; exec "$command"; } while (<F>) { $buffer .= $_; $cache->set($session, [0, $buffer]); }

    And it still waits until the process completes to give me back any output whereas if I run $command from the command line it gives me real-time feedback.

    CT

    Charles Thomas
    Madison, WI
      The problem is not the browser timing out, but rather that the process waits until the end to display the results.

      You may have a different problem, but merlyn's article is still a possible solution. Have your lengthy process fork off and write its output to a file, then have the CGI refresh every X seconds, reading that output file, and displaying the results. Perhaps you could even parse the output file and make the results a bit more user friendly (this is just speculation -- the output may already be user friendly).

      You may also find that your lengthy process buffers its output writing to the file, though. In that case, you can investigate some of the solutions sgifford recommended.

        Have your lengthy process fork off and write its output to a file, then have the CGI refresh every X seconds, reading that output file, and displaying the results.

        Currently the lengthy process has its output appended to a cache file which is read by the script every 5 seconds, as outlined in Merlyn's article.

        CT

        Charles Thomas
        Madison, WI