0
votes

I have a cgi script which takes few parameter like below.

testScript.cgi?arg=1&arg2=SomeThingElse&arg3=otherThing.....

The above script works well and perfectly.

Now I have another perl cgi script called mySecondScript.cgi . It does its own thing but I want to call textScript.cgi with arguments which are calculated in this script. How do I do that. Any elegant solution will be appreciated.

2

2 Answers

1
votes

You probably want to use LWP::Simple to call the second program. Inside mySecondScript.cgi you would need something like this:

my $output = get("http://someserver.somedomain/testScript.cgi?arg=1&arg2=SomeThingElse&arg3=otherThing");

This will return the output from the CGI program (i.e. the HTML page that it generates). If you want more control over what you get back, then you need to use LWP::UserAgent.

my $ua = LWP::UserAgent->new;
my $resp = $ua->get("http://someserver.somedomain/testScript.cgi?arg=1&arg2=SomeThingElse&arg3=otherThing");

$resp will be an HTTP::Response object.

Alternatively, if both of your program are running locally, it might be more convenient to refactor the important bits of testScript.cgi into a module that you can just load and use within mySecondScript.cgi.

-1
votes

There are several ways of calling a "system call" from inside of an perl script. That might be any shell operation or even another perl script. My favorite is qx/[command]/

Look at this mini example to see how it works

my $result = qx/pwd/;
print "result: $result\n";

pwd is a shell command, as would be in your case eg

my $result = qx/mySecondScript $param1 $param2/;

This way you can even tunnel the results from the inner script to the outer script. Other ways could be backticks or the "system" command, but qx ist my personal favorite.