I've got a CGI script which does some lengthy processing and reports the results to the user. Right now I'm doing something like this:

#===== Open I/O pipes and run the process $pid = open3(\*DEV_NULL, \*OUT, \*ERR, "$my_long_process"); #===== Print the results while (<OUT>) { $buffer .= "$_<br>"; #===== Update the display cache $cache->set($session, [0, $buffer]); }

Which works, except it waits until $my_long_process completes before it sends any output back to the browser. If my_long_process takes an hour to run, the browser sits there for an hour with no updated information.

If I run my_long_process from the command line, however, it updates as it goes, so that the user knows what's going on.

Is there a way to set open3() to an unbuffered mode so it returns what my_long_process is doing in real time instead of waiting until the end?

Failing that, is there a better way to do this long process in the fork such that I can get its results as its doing things rather than waiting until the end?

Thanks!

CT

Charles Thomas
Madison, WI

In reply to Long Process Waits Until End to Display Results by C_T

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.