in reply to LWP Forking

I am assuming that the parent CGI script is trying to call another CGI script on the same web server. In that case, you don't need to use LWP. The parent can execute the other CGI script directly. Although, if the parent detaches from child, then the child has no way to communicate back to the browser.

The reason system doesn't work is that it waits for the child process to return. The solution is to use fork and then exec. When running under a web server, you must close STDERR and STDOUT, or the browser won't know that the CGI script has finished.

if ($pid = fork()) { # parent } else { die "Cannot fork:$!" unless defined $pid; close(STDOUT); close(STDERR); exec("otherscript.pl"); }

Replies are listed 'Best First'.
Re: Re: LWP Forking
by Mitch (Sexton) on Apr 21, 2003 at 21:19 UTC
    Hi, I tried your example, but I get a memory error - Un handled Win32 exception error in perl.exe. I have previously read that the fork function in unreliable when being used on Win32 systems.

      Threads, with which fork is emulated on Win32, have some problems in perl 5.6.1. I ran into the issue a little while ago, myself.

      If you are able to upgrade to 5.8.0, I found it works much better in this regard. Though, since you apparently got it working using Win32::Process, it's not really necessary. :)

      bbfu
      Black flowers blossom
      Fearless on my breath