I've got a CGI script which I need to call another perl script (myscript.pl) in the background (non-blocking) and then continue on displaying the HTML headers.
I use a $step variable, where $step=0 indicates to launch the Perl script and then $step automatically increments with each automatic page refresh. The page refresh is necessary to display real-time output.
My issue is that the call to myscript.pl seems to block and doesn't display any HTML when step=0 is passed as a CGI parameter - although the script is still launched. How can I correct this behavior to make the call non-blocking and display the HTML page? Thanks.
use warnings;
use strict;
use CGI;
use Proc::Background;
my $args = new CGI;
if(!defined $args->param('step'))
{
print $args->header;
blah blah blah
print $args->end_html;
exit;
}
if($args->param('step') == 0)
{
$step = 1;
my $proc1 = Proc::Background->new("perl","./myscript.pl","arg1","arg
+2");
}
elsif($args->param('step') > 0)
{
$step = $args->param('step');
$step ++;
}
print $args->header(-Refresh=>"5;url=http://localhost/cgi-bin/mycgi.pl
+?step=$step");
...
print <input type=\"hidden\" name=\"step\" value=\"$step\">";
print $args->end_html;
exit;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.