develooper Front page | perl.beginners | Postings from January 2002

Re: call a cgi script

Thread Previous | Thread Next
Jenda Krynicky
January 30, 2002 08:04
Re: call a cgi script
Message ID:
From:           	"mb" <>
> Is there a way to call a cgi script from another one(diff using html
> header and forms). So that this script get params and return values
> ... a kind of sub.


1) If it's on the same server as your CGI and expects to be used that way 
you can run it via do() or require().

2) If it's on the same computer, but has to be treated as a complete CGI, 
you may use system() or `` or open(PIPE, '|'), open2() or open3().

You will probably need to change the contents of %ENV to pass it the right 
parameters. Eg. if you want to call 
this way you will have to set
	use FindBin qw($Bin);
	$ENV{PATH_TRANSLATED} = $Bin . '/';
	$ENV{QUERY_STRING} = 'name=Jenda';
before you start the (Some of those may not be used by the CGI in 
question. If you know for sure, you can skip them. Also I assume your code 
runs as a CGI, otherwise you'd have to set a few more to fool the other 
script into believing that it's being run as a CGI.)

If you need to post data to the script you'll need to use open2() or open3() 
(read perldoc IPC::Open2 and perldoc IPC::Open3) and send the posted 
data to the other script's STDIN.

3) If the other script is on a different server you will use LWP (Either 
LWP::Simple or LWP::UserAgent, read the docs.) to send a normal HTTP 
request to the other server.


=========== == ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain.
I can't find it.
					--- me

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About