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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Post to two separate CGI scripts at once.

Status
Not open for further replies.

CSpannos

IS-IT--Management
Mar 21, 2001
32
US
Hello,

Is it possible to invoke two different CGI scripts written in Perl at the same time. I have a script that writes its output to a file. I would like to output the same information to another file, like a backup, only without having to copy the file every time an operation takes place. For example, can I do something like this? -->

Code:
<form action=&quot;[URL unfurl="true"]http://www.mypage.com/cgi-bin/script1.cgi&quot;,[/URL] &quot;[URL unfurl="true"]http://www.mypage.com/cgi-bin/script2.cgi&quot;[/URL] method=&quot;POST&quot;>

I know my syntax is probably wrong, but hopefully what I need makes more sense. All information posted on the form gets submitted to the two scripts at the same time.

Thanks!
Kosta
 
I don't think so. One script gets the form data and spits out the browser output, there'd have to be some way to distinguish who would reply back to the browser. Bets are good you could just call the script that saves the data from the action script, or maybe even include it in the action, just call its function and what not. ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Of course:
Use javascript to process the results
of your form entry and then onClick
have a handler send to one url,
retrieve result, and then to the other,
both the result pages opening a new window.

 
marsd, do you think you can post an example?

Thanks so much!
kosta
 
Here's a sample function, adapted from a working site.
Hope you get the gist of it since I may not be able to
get back to you today ;).

function masterurl() {
if (document.formname.elements[0].checked) {
var y = 0;
} else {
var y = 1;
}

var val1 = &quot;?var1=&quot;+y;
var val2 = &quot;&var2=&quot;+document.formname.formdropdown.options[document.userstuff.Ubox.selectedIndex].value;
var val3 = &quot;&var3=&quot;+document.userstuff.userreport.value;
var urlencode = val1.concat(val2,val3);
var loc1 = &quot; var loc2 = &quot; open(loc1,&quot;First CGI opener&quot;, height=400, width=400);
open(loc2,&quot;Second CGI opener&quot;, height=400, width=400);
return true;
}
 
You could use the LWP::Simple module from within the first piece of CGI to make an http call to the second.

See the docs for LWP::Simple.

In the first CGI, do something like,

Code:
#!/usr/local/bin/perl
use LWP::Simple;
my $url = '[URL unfurl="true"]http://server/cgi-bin/second.cgi';[/URL]
$page_from_secondCGI = get($url);

If LWP::Simple does give you enough control, see LWP::UserAgent.

With this, you could chain together as many CGI calls as you want. '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