in reply to Forking in a CGI program on Windows systems

What I want to do is to fork a separate process that would deal with saving this information, so that the CGI program can just return the web page and exit.

So then you really don't need to fork do you? Why not have the CGI script output the HTML to show it's done and then run a seperate Perl script that will save the information?

  • Comment on Re: Forking in a CGI program on Windows systems

Replies are listed 'Best First'.
Re: Re: Forking in a CGI program on Windows systems
by relax99 (Monk) on Nov 08, 2002 at 16:53 UTC

    I'd be glad to do what you suggested - I just don't know how. Maybe I'm misunderstanding something about web servers, but I'm really really not sure how to run something from a CGI program after it has finished.

    Perhaps you could provide a couple of lines of sample code? (Only if it's not too much to ask for, of course.)

      Something like this should work:

      @args = ("command", "arg1", "arg2"); system(@args) == 0 or die "system @args failed: $?";

      Update: Or maybe this is better since exec() doesn't return to the current script:

      @args = ("command", "arg1", "arg2"); exec { $args[0] } @args or print STDERR "couldn't exec $args[0]: $!";

        I do appreciate that you were trying to help... Unfortunately, the above would not work. Just for the notes - quote from the Camel Book (3rd edition, p. 811) - "The system function works exactly like exec, except that system does a fork first and then, after the exec, waits for the executed program to complete." That's exactly what prevents me from envoking an external program using exec or system - I need my CGI program to completely finish and exit BEFORE the child process finishes.

        There's a similar post "Understanding fork" by neiwatson. I'll try some of the suggestions offered there, even though I'm not sure to what extent they are applicable to Windows systems. I was just wondering if anyone had experience forking on Windows systems from a CGI program (it's important for it to be a CGI program, i.e. run on a web server)