我想通过 PHP 执行一个 Perl 脚本。我使用 exec()
来执行 Perl 脚本,在我的本地机器上可以工作,但是在服务器上无法工作。服务器基于 CentOS Linux。
我已经为 PHP 和 Perl 脚本文件赋予了完全权限(777)。当我尝试执行时,错误日志中出现以下错误:
sh: /perl: No such file or directory
我尝试过以下几种方式来执行:
exec("perl -w Script.pl $username $password",$output);
exec("/usr/bin/perl -w Script.pl $username $password",$output);
exec("/usr/bin/perl Script.pl $username $password",$output);
我还尝试使用system
函数
$output = system("perl Script.pl $username $password");
我尝试了这个,但没有反应。
我还尝试使用 passthru()
函数执行 Perl。
passthru("/usr/bin/perl -w Script.pl $username $password",$output);
当我执行这行代码时,$output
打印出 127,并且脚本没有任何反应。
我使用 is_executable()
函数检查文件是否可执行。结果显示该文件不可执行。
以下是代码:
$file = 'Script.pl';
if (is_executable($file))
{
echo $file.' is executable';
}
else
{
echo $file.' is not executable';
}
如果我通过终端执行perl脚本,那么它可以正常工作,但是当我尝试通过PHP来执行时,它就无法正常工作。
ls
或cwd
这样的简单命令进行检查。如果您只是在命令行上使用perl解释器执行perl脚本,则不必设置执行权限。664
应该可以。否则,如果服务器以这种方式设置,则可以从浏览器中执行它。 - simbabque