Gossamer Forum
Home : General : Perl Programming :

Calling a cgi script inside another cgi script passing variables

Quote Reply
Calling a cgi script inside another cgi script passing variables
I have read many posts about this but have so far been unable to get my script to call another of my scripts passing variables along with it

NOTE: Both my scripts are in the same directory on the same server



(ScriptA.cgi)

#!/usr/local/bin/perl

print "Content-type: text/html\n\n";

#GET QUERY ATTRIBUTES
$source = $ENV{'QUERY_STRING'};
@pairs = split(/&/, $source);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%(..)/pack("c", hex($1))/eg;
$SOURCE{$name} = $value;
print "name- $name = $value <BR>"; #DEBUG
}

local ($page) = "";

$SubPage = "ScriptB.cgi?LoginId=$FORM{'LoginId'}&Password=$FORM{'Password'}";

$OutPut = qx|perl $SubPage|;

$page = $page . $OutPut;

print $page;



(ScriptB.cgi)

#!/usr/local/bin/perl

print "Content-type: text/html\n\n";

$test = $ENV{'QUERY_STRING'};

@pairs = split(/&/, $test);

foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%(..)/pack("c", hex($1))/eg;

$FORM{$name} = $value;
print "name- $name = $value <BR>"; #debug
}




NOTE: I need these to be in separate scripts

Any help would be greatly appreciated

Cheers

Jeff
Quote Reply
Re: [encino] Calling a cgi script inside another cgi script passing variables In reply to
Try:

Code:
{
local $ENV{QUERY_STRING} = "LoginId=$FORM{'LoginId'}&Password=$FORM{'Password'}";
$OutPut = qx|perl ScriptB.cgi|;
}

Btw, mixed case variables are far easier to get mixed up, causing errors, and make it harder to debug.
Quote Reply
Re: [Paul] Calling a cgi script inside another cgi script passing variables In reply to
I tried using your suggestion but I had no luck

The second script doesn't seem to accept the parameters

Thanks anyway

If there are any other ideas please let me know

Cheers

Jeff
Quote Reply
Re: [encino] Calling a cgi script inside another cgi script passing variables In reply to
Seems to work for me.

Script 1:

Code:
#!/perl/bin/perl
#======================================

use strict;
main();

#======================================

sub main {
#--------------------------------------
# Test.

local $ENV{QUERY_STRING} = q|name=paul|;
print "Content-type: text/plain\n\n";
print qx/perl test2.cgi/;
}

Script 2:

Code:
#!/perl/bin/perl
#======================================

use strict;
main();

#======================================

sub main {
#--------------------------------------
# Test.

print "You passed in: $ENV{QUERY_STRING} to $0";
}

Output:

You passed in: name=paul to test2.cgi
Post deleted by encino In reply to
Quote Reply
Re: [Paul] Calling a cgi script inside another cgi script passing variables In reply to
I got it working

thanks for your help

Cheers

Jeff