2012-06-20 47 views
9

可能重复:
Calling Perl script from PHP and passing in variables, while also using variablized perl script name执行Perl在PHP

我想通过PHP执行perl脚本。我使用exec()来执行perl脚本。它在我的机器上工作,但在服务器上不起作用。该服务器基于CentOS Linux。

我给了PHP和perl脚本文件的完全权限(777)。当我尝试执行,我得到以下错误的error_log

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()功能

passthru("/usr/bin/perl -w Script.pl $username $password",$output); 

当我执行这一行执行Perl,$output打印127并没有任何反应脚本。

我用is_executable()函数检查文件是否可执行。它显示该文件不可执行。

代码如下

$file = 'Script.pl'; 

if (is_executable($file)) 
{ 
    echo $file.' is executable'; 
} 
else 
{ 
    echo $file.' is not executable'; 
} 

如果我通过终端执行Perl,它工作正常,但是当我试图通过PHP执行,它不工作。

+0

变化'ust'到'usr' – k102

+0

@ K102对不起亚...我错误地在这个岗位类型.. –

+0

@Gordon感谢您的链接..我仍然有相同的问题.. –

回答

6

使用完整路径执行脚本。

exec("/usr/bin/perl /full/path/to/Script.pl $username $password",$output); 

问候,

+0

我已经试过这个..不工作。 –