我有一个cgi脚本,该脚本调用了另一个cgi脚本.
I have a cgi script that calls another cgi script.
main_script.cgi脚本如下:
main_script.cgi script looks like this:
print qx/child_script.cgi arg1=foo arg2=bar/;child_script.cgi看起来像这样:
child_script.cgi looks something like this:
use CGI; use Data::Dumper; my $query = CGI->new; warn Dumper($query);如果我在外壳中执行./main_script.cgi,则会得到:
If I do ./main_script.cgi in the shell, I get:
$VAR1 = bless( { '.parameters' => [ 'arg1', 'arg2' ], 'use_tempfile' => 1, '.charset' => 'ISO-8859-1', '.fieldnames' => {}, 'param' => { 'arg1' => [ 'foo' ], 'arg2' => [ 'bar' ] }, 'escape' => 1 }, 'CGI' );但是,如果我在浏览器中访问myhost/main_script.cgi,则输出为:
But if I visit myhost/main_script.cgi in the browser, the output is:
$VAR1 = bless( { '.parameters' => [], 'use_tempfile' => 1, '.charset' => 'ISO-8859-1', '.fieldnames' => {}, 'param' => {}, 'escape' => 1 }, 'CGI' ); 推荐答案您的辅助脚本正在从您的第一个脚本继承%ENV .如果 CGI 看到 REQUEST_METHOD ,它将忽略命令行参数,而是从 QUERY_STRING 等中加载内容.
Your secondary script is inheriting %ENV from your first script. If CGI sees a REQUEST_METHOD it ignores the commandline parameters and instead loads things from the QUERY_STRING, etc.
要解决此问题,您必须首先本地化%ENV 并删除 REQUEST_METHOD .
To fix this, you must first localize the %ENV and delete the REQUEST_METHOD.
以下内容证明了这一点:
The following demonstrates this:
part1.pl
#!perl use strict; use warnings; use CGI; use Data::Dump; my $q = CGI->new; print "Content-type: text/plain; charset=iso-8859-1\n\n"; dd $q; # Localize the REQUEST_METHOD so that the secondary process doesn't see it. my $text = do { local $ENV{REQUEST_METHOD}; qx(perl part2.pl arg1=val1 arg2=val2); }; print $text;part2.pl
#!perl use strict; use warnings; use CGI; use Data::Dump; my $q = CGI->new; print "Content-type: text/plain; charset=iso-8859-1\n\n"; dd $q;访问 localhost/cgi-bin/part1.pl?a = 1& b = 2 会显示以下内容:
bless({ ".charset" => "ISO-8859-1", ".fieldnames" => {}, ".parameters" => ["a", "b"], "escape" => 1, "param" => { a => [1], b => [2] }, "use_tempfile" => 1, }, "CGI") Content-type: text/plain; charset=iso-8859-1 bless({ ".charset" => "ISO-8859-1", ".fieldnames" => {}, ".parameters" => ["arg1", "arg2"], "escape" => 1, "param" => { arg1 => ["val1"], arg2 => ["val2"] }, "use_tempfile" => 1, }, "CGI")更多推荐
CGI命令行Args消失
发布评论