poprishchin has asked for the wisdom of the Perl Monks concerning the following question:

I have a form submitting data to newComp.pl - that script needs to do its thing, and then run admin.pl, sending it scalar arguments that it created. admin.pl then does it's thing and outputs to the browser. I've tried. do 'admin.pl?msg=Success'; with no luck. I've also tried
system(); eval ``'
and plain old backticks with no luck. Any suggestions? Seems like a real remedial thing but I can't figure it out. Thanks.

Replies are listed 'Best First'.
Re: running a CGI script from another CGI script
by tachyon (Chancellor) on Oct 11, 2004 at 00:47 UTC

    Normally you structure your code a little better. When CGI stuff "does not work" you should check the error logs which usually indicate *why* it does not work. See CGI Help Guide and particularly the bit about error_log. Assuming that admin.pl uses the CGI module and is in the same dir as the calling script then this should work:

    exec( "./admin.pl msg=Success" );

    script?some=arg syntax is HTTP syntax, not OS calling syntax. You have to use syntax your OS understands. Alternatively your newComp.pl script could do this:

    use CGI; my $q = new CGI; # do stuff, generate message print $q->redirect( "http://domain.com/cgi-bin/admin.pl?msg=$MESSAGE" +);

    If your scripts are not using CGI then you should probably start now. use CGI or die. I would suggest moving the functions or both scripts into a module(s) and then just having the scripts call the module functions. This is much more flexible. See Simple Module Tutorial

    cheers

    tachyon

Re: running a CGI script from another CGI script
by Happy-the-monk (Canon) on Oct 11, 2004 at 00:40 UTC

    I've tried. do 'admin.pl?msg=Success'

    Try the script on the command line. If it is called the way you say, on the command line it will be 'admin.pl msg Success' or 'perl admin.pl msg Success' with spaces between the name(s) and argument(s).

    If that works, try the same with backticks or   qx()   from the CGI script.
    If that doesn't work, but the latter did work, you are having some sort of permission issue.

    You could also think about using Location headers to call the other script the HTTP way by help of the browser.
    Another way still would be to use LWP::Simple.

    Cheers, Sören

Re: running a CGI script from another CGI script
by Prior Nacre V (Hermit) on Oct 11, 2004 at 09:38 UTC

    Have you tried the HTTP Location header.

    I have used this successfully in the type of situation you are describing.

    Regards,

    PN5