【发布时间】:2010-12-23 15:07:35
【问题描述】:
我正在尝试从另一个 Perl 模块在当前环境中运行 CGI 脚本。使用 GET 请求的标准系统调用一切正常。 POST 也很好,直到参数列表变得太长,然后它们被切断。
有没有人遇到过这个问题,或者对其他尝试方法有什么建议?
为清楚起见,以下内容有所简化。还有更多的错误检查等等。
对于 GET 请求 和 不带参数的 POST 请求,我执行以下操作:
# $query is a CGI object.
my $perl = $^X;
my $cgi = $cgi_script_location; # /path/file.cgi
system {$perl} $cgi;
- 参数通过 QUERY_STRING 环境变量。
- STDOUT 被调用方捕获 脚本所以无论 CGI 脚本 打印行为正常。
- 这部分有效。
对于 带有参数的 POST 请求,以下工作有效,但似乎限制了我的可用查询长度:
# $query is a CGI object.
my $perl = $^X;
my $cgi = $cgi_script_location; # /path/file.cgi
# Gather parameters into a URL-escaped string suitable
# to pass to a CGI script ran from the command line.
# Null characters are handled properly.
# e.g., param1=This%20is%20a%20string¶m2=42&... etc.
# This works.
my $param_string = $self->get_current_param_string();
# Various ways to do this, but system() doesn't pass any
# parameters (different question).
# Using qx// and printing the return value works as well.
open(my $cgi_pipe, "|$perl $cgi");
print {$cgi_pipe} $param_string;
close($cgi_pipe);
- 此方法适用于短参数列表,但如果整个命令接近 1000 个字符,则参数列表会缩短。这就是我尝试将参数保存到文件的原因;以避免外壳限制。
- 如果我从执行的 CGI 脚本中转储参数列表,我会得到如下内容:
param1=blah
... a bunch of other parameters ...
paramN=whatever
p <-- cut off after 'p'. There are more parameters.
我做过的其他没有帮助或工作的事情
- 关注CGI troubleshooting guide
- 使用 CGI->save() 将参数保存到文件中,将该文件传递给 CGI 脚本。使用此方法仅读取第一个参数。
$> perl index.cgi < temp-param-file
- 将 $param_string 保存到一个文件中,将该文件传递给 CGI 脚本,就像上面一样。与通过命令行传递命令的限制相同;仍然被切断。
- 确保
$CGI::POST_MAX的高值可以接受(为-1)。 - 确保 CGI 的命令行处理工作正常。 (:no_debug 没有设置)
- 使用相同的参数从命令行运行 CGI。这行得通。
潜在客户
- 显然,这似乎是 Perl 用于执行命令的 shell 的字符限制,但无法通过文件传递参数来解决。
【问题讨论】: