in reply to Have perl to start another perl script

Hi,

Do it in many ways! put either of the following in your a.cgi, to invoke b.cgi

  1. system("b.cgi");
  2. exec("b.cgi");
  3. `b.cgi`

Other options available are Threads and fork. These two are intended to have the parent monitor the child easily. Please refer to documentation for details.

Cheers !

--VC

There are three sides to any argument.....
your side, my side and the right side.

Replies are listed 'Best First'.
Re^2: Have perl to start another perl script
by hakana (Acolyte) on Jul 27, 2007 at 10:36 UTC
    I would like to "daemonizat" the other perl script and completly dissociate it from the parent script. But save the child pid to a file. I tried the following but the system returns 0 as pid.
    $pid = system("other.pl $IPaddress &"); #my $pidfile = "/home/ember/devices/$Macaddress/$pid.pid"; #open (FILE, "> $pidfile") or die "Can't open file $pidfile\n"; #close FILE;

      You can start the script and obtain the pid using a piped open.

      my $pid = open KID, "| /path/to/your/perl theScript.pl" or die ... print KID $IPAddress; close KID;

      I'm not sure if there are any caveats with this on your platform.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      system always returns 0 on successful launch. I recommend you do all the pid-saving in a wrapper shellscript (or Perlscript) around your child program:

      #!/usr/bin/perl -w use strict; my $pid = $$; my ($IPaddress) = @ARGV; # Save our PID into the pidfile: my $pidfile = "/home/ember/devices/$Macaddress/$pid.pid"; open (FILE, "> $pidfile") or die "Can't create file $pidfile: $!\n"; print FILE "$pidfile\n"; close FILE; # and replace ourselves with the real program, which gets the same PID + as we had: exec 'other.pl', $IPaddress;
        The code worked fine but since it's a .cgi that starts the second script it's started as apache and after 120 sec the process is killed due to inactivity (send/reciv).

        Any one that has a solution to this?
      • Start as other user
      • remove timeout in httpd.conf?