Thread: cgi query

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    2
    Rep Power
    0
    I have a perl script, blah.cgi in local cgibin directory on a unix box running apache - works fine. I would like it to call another perl script (preferably spawning it off) called child.cgi.

    1) can I exec it with
    $foo="child.fgi"
    exec ($foo) or die ("Aaargh");

    2) should I system() it instead ?

    3) should child.cgi have some kind of path in front (where does apache look?)?

    many thanks
  2. #2
  3. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>1) can I exec it with $foo="child.fgi"..
    it depends

    >>2) should I system() it instead ?
    Maybe not. Please specify exactly what blah.cgi and child.cgi do, maybe I can think of another way of doing the exact task

    >>3) should child.cgi have some kind of path in front
    You can just treat it as a normal cgi file like having #!/usr/local/bin/perl at the first line
  4. #3
  5. No Profile Picture
    ledjon
    Guest
    Devshed Newbie (0 - 499 posts)
    The best thing to do (assuming child.cgi isn't run for anything but this) is to make the stuff in child.cgi, or at least the part you want to called, a sub routine. then you can require 'child.cgi'; and call the sub routine.
  6. #4
  7. No Profile Picture
    ledjon
    Guest
    Devshed Newbie (0 - 499 posts)
    Another thing you can do (if you want this called to a webpage or from a remote server) is to use the libwww-perl library. (You have to have that installed on the server).

    Then in the cgi file that calls it use the following:
    --------------------
    #!/usr/bin/perl

    #
    #Remote Include
    #by: Jon Coulter - ledjon@ledjon.com
    #

    ####URL of File to be Included - Full URL####
    $url = "http://www.yoursite.com";

    ####Use libwww-perl####
    use LWP::Simple;

    ####Header####
    print "Content-type: text/htmlnn";

    ####Do some checking!####
    #This check to see if something like "script.pl?http://www.asdf.com/asdf.cgi" has been called.
    #If there's nothing entered it used the default (defined above).
    $qstring = $ENV{'QUERY_STRING'};
    if ($qstring ne "") {$url = $qstring}

    ####Get the Info!####
    $script_output = getprint("$url");

    ####Print it out####
    print "$script_output";
    ----------------------

    Note: That's a completly working script I wrote that called remote (meaning on a different server) files for includes. I use it alot at work.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    2
    Rep Power
    0
    More to the point, what child.cgi is required to do is to 'clean up' after normal routines - The cgi process creates some workfiles, but I need to cope with the fact that some user will get part way thru the process then wander off elsewhere. So I need a job to wait nn minutes then activate and purge workfiles (naturally created with $$ in name, and $$ passed to child as targets to kill after sleep nn*60.)

    So I thought - why not & off a job to shell, let it sleep a bit then asassinate workfiles.

    Am I approaching this wrong ?

    D

IMN logo majestic logo threadwatch logo seochat tools logo