我想从Apache Perl CGI脚本执行Perl脚本。
CGI可以很好地显示HTML文本,但是当我尝试使用qx//
执行另一个脚本时,它无法正常工作。
<!DOCTYPE HTML>
<html>
<head>
<title>SUMAR</title>
</head>
<body>
<center>
<h1>Registro de usuario</h1>
<form method="get" action="cgi-bin/index.cgi">
Nombre <input type="text" name="name">
<br>
<br>
Usuario <input type="text" name="user">
<br>
<br>
Contraseña <input type="text" name="pass">
<br>
<br>
Correo electronico <input type="text" name="email">
<br>
<br>
<input type="submit" value="Enviar">
</form>
</center>
</body>
</html>
#!/usr/bin/perl
use Unix::Passwd::File;
use File::Path;
use CGI;
use strict;
my $cgi = new CGI;
my $name = $cgi->param("name");
my $user = $cgi->param("user");
my $pass = $cgi->param("pass");
my $email = $cgi->param("email");
print "Content-type: text/html\n\n";
print "<html>\n<body>\n";
print $name . $user . $pass . $email;
print "\n</body>\n</html>";
qx(perl index.pl);
当我从命令行执行CGI时,对index.pl
的调用工作正常,但是当我尝试通过网络时,它无法正常工作。
EDIT :::::::::::::::。
apache2/error.log
.....
[Mon May 07 12:31:41.070830 2018] [cgid:error] [pid 6039:tid 139761641543424] [client 172.28.200.230:59210] End of script output before headers: index.cgi, referer: http://172.20.3.107/
[Mon May 07 12:50:14.129598 2018] [cgid:error] [pid 6523:tid 139761926846336] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/index.pl' failed
[Mon May 07 12:50:14.130080 2018] [cgid:error] [pid 6040:tid 139761717077760] [client 172.28.200.230:59324] End of script output before headers: index.pl, referer: http://172.20.3.107/
mkdir /home/hgjhh: Permission denied at index.pl line 23.
mkdir /home/hgjhh: Permission denied at index.pl line 23.
[Mon May 07 13:15:25.420469 2018] [cgid:error] [pid 6040:tid 139761599579904] [client 172.28.200.230:59613] AH01264: script not found or unable to stat: /usr/lib/cgi-bin/index.pli
mkdir /home/hgjhh: Permission denied at /usr/lib/cgi-bin/index.pl line 23.
mkdir /home/hgjhh: Permission denied at /usr/lib/cgi-bin/index.pl line 23.
[Mon May 07 13:26:56.046889 2018] [mpm_event:notice] [pid 6035:tid 139761926846336] AH00491: caught SIGTERM, shutting down
[Mon May 07 18:22:57.342819 2018] [mpm_event:notice] [pid 534:tid 140120374777728] AH00489: Apache/2.4.10 (Debian) configured -- resuming normal operations
[Mon May 07 18:22:57.364426 2018] [core:notice] [pid 534:tid 140120374777728] AH00094: Command line: '/usr/sbin/apache2'
答案 0 :(得分:1)
您正在假设当前的工作目录可能不正确。
如果index.pl
与CGI脚本位于同一目录中,
qx(perl index.pl);
应该是
use FindBin qw( $RealBin );
use String::ShellQuote qw( shell_quote );
my $cmd = shell_quote("perl", "--", "$RealBin/index.pl");
qx($cmd);
或
use FindBin qw( $RealBin );
use IPC::System::Simple qw( capturex );
capturex("perl", "--", "$RealBin/index.pl");
在这两种情况下,如果"perl", "--", "$RealBin/index.pl"
可执行,"$RealBin/index.pl"
可以缩减为index.pl
。
这可能是也可能不是您唯一的问题。在您告诉我们您遇到了什么问题之前(例如告诉我们您遇到了什么错误),我们无法继续提供帮助。
答案 1 :(得分:-3)
您可以这样使用系统:
system("/path/to/index.pl", @args);