在PHP中执行Perl [英] Execute perl in PHP

查看:172
本文介绍了在PHP中执行Perl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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脚本文件都给予了完全许可(777).当我尝试执行时,我在error_log中得到以下错误

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

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

我也尝试过使用system函数

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

尝试此操作没有任何反应.

Nothing happening when I try this.

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

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

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

执行此行时,$output打印127,脚本中什么也没有发生.

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

我用is_executable()功能检查了文件是否可执行.它表明该文件不可执行.

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

代码如下

$file = 'Script.pl';

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

如果我通过终端执行perl,则可以正常运行,但是当我尝试通过PHP执行时,则无法正常运行.

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

推荐答案

使用完整路径执行脚本.

Use full path to execute the script.

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

此致

这篇关于在PHP中执行Perl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆