在 PHP 中执行 perl

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11114277/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:46:12  来源:igfitidea点击:

Execute perl in PHP

phpperlshellexec

提问by Suresh kumar

Possible Duplicate:
Calling Perl script from PHP and passing in variables, while also using variablized perl script name

可能的重复:
从 PHP 调用 Perl 脚本并传入变量,同时还使用可变的 perl 脚本名称

I want to execute a perl script through PHP. I use exec()to execute the perl script. It works in my machine but does not work on the server. The Server is based on CentOS Linux.

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

I gave full permission (777) to both the PHP and the perl script file. When I try to execute, I get the following error in error_log

我对 PHP 和 perl 脚本文件都给予了完全许可 (777)。当我尝试执行时,我在 error_log 中收到以下错误

sh: /perl: No such file or directory

I tried to execute using the following ways

我尝试使用以下方式执行

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);

I also tried by using the systemfunction

我也尝试过使用该system功能

$output = system("perl Script.pl $username $password");

Nothing happening when I try this.

当我尝试这个时什么也没有发生。

I also tried to execute perl by using the passthru()function

我还尝试使用该passthru()函数执行 perl

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

When I execute this line, $outputprints 127 and nothing happens in the script.

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

I checked whether file is executable or not with the is_executable()function. It shows that the file is not executable.

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

Code as below

代码如下

$file = 'Script.pl';

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

If I execute perl through the terminal, it works fine but when I try to execute through PHP, it is not working.

如果我通过终端执行 perl,它工作正常,但是当我尝试通过 PHP 执行时,它不起作用。

回答by user1126070

Use full path to execute the script.

使用完整路径来执行脚本。

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

Regards,

问候,