in reply to Re: (2) Launch background perl script from CGI
in thread Launch background perl script from CGI

Didn't I say spawn the script in background? ;-)

In your cgi script, you just need to do this to kick off a background process -
# check if the 'Generate Report' button is clicked # if so, then set $generate_report to true. if ($generate_report) { # kick off background processing `C:\\Perl\\bin\\perl.exe generate_report.pl &`; # print some feedback text back to user print $cgi->header, $cgi->start_html, "The generate_report.pl script has started in background", $cgi->end_html; }
Where the back quotes `` tell perl to run the generate_report.pl script, and the '&' at the end puts the script in background. Your CGI script will return control immediately to the browser, leaving the report generation script to run in the background (without interfering with the browser).

Replies are listed 'Best First'.
Re: (4) Launch background perl script from CGI
by Anonymous Monk on Dec 11, 2003 at 06:30 UTC
    Sorry I missed that!
    However, `C:\\Perl\\bin\\perl.exe generate_report.pl &`; does not work in win-2000. It still runs the job in the foreground!

      I believe the 'quick-and-dirty' way to run a process in the background on a Win32 platform is:

      system('start /b yourcommand');

      HTH

      --
      3dan

      The & worked for me on XP so I assumed that it would work for you. Anyway, there are several modules that will create background processes for you on Windows NT/2K/XP platforms. Such as Proc::Background and Win32::Process on CPAN.
      use Proc::Background; my $proc = Proc::Background->new("C:\\Perl\\bin\\perl.exe generate_rep +ort.pl");
      Will kick off a background process via Win32::Process, instead of relying on the shell to create a background process.