Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run a cgi from another cgi

Status
Not open for further replies.

RichMarc

Programmer
Jan 8, 2003
1
GB
This may have been asked before, if so sorry, the search dont work.. and I dont see a same/like topic ..

All I want to do is have my cgi prog (prog1.pl) run my (prog2.pl) then return to my prog1.pl ..

#prog1.pl
print &quot;I am in prog1.pl<br>\n&quot;;
#run the cgi &quot;prog2.pl&quot;;
print &quot;back in prog1.pl<br>\n2;

#prog2.pl
print &quot;hello for prog2.pl<br>\n&quot;;
exit;

so the output I want through the browser wants to be
I am in prog1.pl
hello from prog2.pl
back in prog1.pl

If I use system &quot;/user/bin/perl prog2.pl&quot; I get the output
I am in prog1.pl
back in prog1.pl

so although it 'finds' prog2.pl prog2.pl seems just not to run and generate the output..

Obviously prog1 and prog2 are quite large :) I also need to pass vars into prog2 (none need come out though) I can probaly do that if I can get somet output from prog2.

Both prog1 and prog2 work properly from the browser. It seems like the output from prog2 is NOT generated to the browser when called from prog1 .. Any help ??
 
if prog2 is a CGI application, then you need to 'speak' to it like it is CGI. So, you typically ask a CGI application to run via an HTTP request to the hosting web server. You can do that easily from within prog1 with the LWP module(s).

If your call to prog2 is fairly simple, then you might use LWP::Simple.

Code:
#!/usr/local/bin/perl
use strict;
use CGI;
use CGI::Carp 'fatalsToBrowser';
use LWP::Simple;

my $cgi_obj = new CGI;
print $cgi_obj->header,
      $cgi_obj->start_html,
      qq(<p>In prog 1</p>);

my $prog2_url = '[URL unfurl="true"]http://server/cgi-bin/prog2.cgi?arg1=key1';[/URL]
my $prog2_page = get($prog2_url);

print qq(<pre>$prog2_page</pre>
      <p>Back in prog 1</p>),
     $cgi_obj->end_html;

If LWP::Simple does not give you enough control, see the perldocs for LWP::UserAgent , like,

prompt> perldoc LWP::UserAgent -Enter-

Note: I have not run the above code. There may be a typo or other gremlin lurking in there. But, hopefully, it illustrates the general idea of issuing an HTTP request from within one piece of CGI to get a response from another.

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top