Hopefully this group of code snips will show you what is going on.

The first part is where I create the fork. The second part is the lengthy process (one of them). The third part is how I display the results so far as processing is ongoing.

It works fine, except it waits until createCommandFiles() is done before displaying the results instead of displaying the results so far.

my $session = getSessionID(); my $cache = getCacheHandle(); $cache->set($session, [0, $buffer]); #===== Fork off a child process to do the processing if (my $pid = fork) { delete_all(); # get rid of old parameters param('session', $session); print redirect(self_url()); } elsif (defined($pid)) { close STDOUT; open (STDOUT, "-|"); #===== Make the command files $buffer .= "<strong>Creating command files...</strong><br>"; $cache->set($session, [0, $buffer]); createCommandFiles($cache); $buffer .= "<strong>Done creating command files.</strong><p>"; $cache->set($session, [1, $buffer]); } # if the pid is defined sub createCommandFiles($) { my $cache = shift or die "Must supply cache to getVersionReports()!\n"; #===== Change directory to our directory chdir($file_dir) or die "Couldn't chdir to $file_dir"; #===== Make each command file foreach my $device (@selected_devices_array) { my $command = "$mkcmdfile -t \"$device\""; system($command) and die "Could not run command $command : $!"; $buffer .= "Created command file for $device.<br>"; #===== Update the display cache $cache->set($session, [0, $buffer]); } } # end of createCommandFiles() #=================================================================== # D I S P L A Y R E S U L T S #=================================================================== sub displayPushResults($) { my $session = shift or die "Must supply session id to displayPushResults()!\n"; my $cache = undef; my $data = undef; #===== Get a cache handle $cache = getCacheHandle(); #===== Get the session info $data = $cache->get($session); #===== Check validity of session die "Could not reconnect to your session!\n" unless ($data and ref $ +data eq 'ARRAY'); #===== Write the header print "Content-type: text/html\n\n"; print "<html>\n"; print "<head>\n"; print "<title>CodePusher.cgi</title>\n"; print "<meta http-equiv=refresh content=5>\n" if (!($data->[0])); print "</head>\n"; print "<body>\n"; AantsHtml::printUWHeader(); #===== Title print "<center><h1>Results</h1></center>\n"; print "<p><p>\n"; #===== Print the results print "$data->[1]"; if (!$data->[0]) { print "<p><font color=red>Still processing... please wait!</font>< +br>"; } # if the code push is not done yet } # displayPushResults()
CT
Charles Thomas
Madison, WI

In reply to Re^6: Long Process Waits Until End to Display Results by C_T
in thread 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.