[英]How can I pass variables from one CGI script to another?
I have a CGI perl script called install-app-pl.cgi
: 我有一个名为
install-app-pl.cgi
的CGI perl脚本:
#!/usr/bin/perl -w
print header('text/html');
use strict;
use CGI ':standard';
# Get me some vars
my @params = param();
my $APP_NAME = param('app_name');
my $APP_WEB_PORT = param('app_web_port');
my $APP_WEB_USER = param('app_web_user');
my $APP_WEB_PASS = param('app_web_pass');
my $DOWNLOAD_DIR = param('download_dir');
my $CONFIG_DIR = param('config_dir');
my $LIBRARY_DIR = param('library_dir');
my $TEMP_DOWNLOAD_DIR = param('temp_download_dir');
# Run another script
if ( $APP_NAME ) {
print "Installing $APP_NAME...";
print "<pre>";
system ("perl /var/www/mysite.local/public_html/lib/$APP_NAME/install-$APP_NAME.pl");
print "</pre>" ;
}
else {
print "No app specified, check the error log";
}
I'm trying to get it to pass the variables defined from the CGI parameters to install-$APP_NAME.pl
我正在尝试将其从CGI参数定义的变量传递给
install-$APP_NAME.pl
#!/usr/bin/perl -w
print header('text/html');
use strict;
use CGI ':standard';
require "/var/www/mysite.local/public_html/cgi-bin/install-app-pl.cgi"
# Echo my vars
print "$CONFIG_DIR $DOWNLOAD_DIR $LIBRARY_DIR $PGID $PUID $TZ $APP_WEB_PORT";
But I'm not sure of the best way to pass those on. 但是我不确定传递这些最好的方法。
Are you sure that install-app-pl.cgi is a CGI program? 您确定install-app-pl.cgi是CGI程序吗? Are you sure that it's not just a Perl command-line program?
您确定它不仅是Perl命令行程序吗? I mean, I see how it's named, but it seems very strange to call a CGI program using
system()
like that. 我的意思是,我知道它的命名方式,但是使用诸如此类的
system()
调用CGI程序似乎很奇怪。
And the difference is crucial here. 在这里,差异至关重要。 CGI programs access their parameters in a different way command-line programs.
CGI程序通过命令行程序以不同的方式访问其参数。
If it really is a CGI program, then you have a few options: 如果它确实是一个CGI程序,那么您有几种选择:
foo=xxx&bar=yyy&baz=zzz
(see the DEBUGGING section of the CGI.pm documentation for details). foo=xxx&bar=yyy&baz=zzz
(有关详细信息,请参见CGI.pm文档的DEBUGGING部分 )。 This, of course, relies on the program using CGI.pm and it feels a bit hacky to me. system()
. system()
从另一个程序进行调用,则该程序是否真的需要成为CGI程序。 And then decide to rewrite it as a command-line program. A few other points about your code. 有关代码的其他几点。
use warnings
pragma. use warnings
。 Most people now use that in place of -w
on the shebang line. -w
。 header()
function before loading the CGI module that defines it. header()
函数似乎很奇怪。 It works, because the use
is handled at compile time, but it would be nice to re-order that code to make more sense. use
是在编译时处理的,但是最好重新排序该代码以使其更有意义。 use strict
(and use warnings
) as the very first things in their program. use strict
(并use warnings
)。 Immediately after the shebang line. system()
returns the return value from the process. system()
返回过程的返回值。 If your second program produces useful output that you want displayed on the web page, you should use backticks instead. <pre>
element, why not just remove that element and return a content type of "text/plain" instead? <pre>
元素中,为什么不删除该元素并返回内容类型为“ text / plain”呢? Update: And I'd be remiss if I didn't reiterate what many people have already said in comments on your original question - this sounds like a terrible idea. 更新:如果我不重申许多人在对您的原始问题的评论中已经说过的话,那我将不予理--这听起来像一个可怕的主意。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.