Gossamer Forum
Home : General : Perl Programming :

Can I call a cgi script from another script?

Quote Reply
Can I call a cgi script from another script?
Let's say for example, there is another cgi script (Script-A) located at a remote server. Script-A outputs a result - lets say, a page count.

I have a script on my own server (Script-B) which I'd like to call the Script-A and "read" the result into an output from Script-B.

In other words, I'd like my Script-B to read the results of Script-A and print the output (whether in an HTML form or direct to browser).

How can this be done? Or can it be done at all?
Quote Reply
Re: Can I call a cgi script from another script? In reply to
Try using the LWP simple module or sockets.

------------------
Chris
Quote Reply
Re: Can I call a cgi script from another script? In reply to
You can find all of the LWP distribution at www.perl.com/CPAN/modules/by-category/15_World_Wide_Web_HTML_HTTP_CGI/LWP/libwww-perl-5.47.tar.gz and the readme is at www.perl.com/CPAN/modules/by-category/15_World_Wide_Web_HTML_HTTP_CGI/LWP/libwww-perl-5.47.readme .

You can find the WIN32 fix at ftp://cogen.mit.edu/software/perl/libwww-win32-fix.zip .

You can use the LWP::SIMPLE module to do something like this.

Code:
#!/usr/bin/perl
use CGI;
use LWP::Simple;
#set URL
$URL="http://www.domain.com/cgi-bin/
your_script.cgi?query=something";
#retrieve the results
$Page=get($URL);

The results of calling the program will be stored in $Page. You may have to parse the results to get what you want.

------------------
Chris

[This message has been edited by Chris071371 (edited January 24, 2000).]
Quote Reply
Re: Can I call a cgi script from another script? In reply to
Thanks, this may sound stupid, but where do I get a LWP module for Win32 or Unix? And how do I set up the script to call an external cgi script and print out the results?
Quote Reply
Re: Can I call a cgi script from another script? In reply to
Thanks Chris. I will try this out. But how is the $weatherURL variable defined?
Quote Reply
Re: Can I call a cgi script from another script? In reply to
Sorry about that, I fixed it. It should have been $URL.

------------------
Chris
Quote Reply
Re: Can I call a cgi script from another script? In reply to
Chris,
The mind boggeling question is -how- or -if- I can compile a private copy of the module that I can up-load to the webserver I'm using wich does not have this particular module installed.

cheers,
floris