2015-10-06 107 views
-1

我正在尝试使用PHP脚本来调用shell脚本并将输出结果输出到浏览器。chdir在PHP脚本中调用shell脚本的问题

我已确认所有权限设置都设置正确,PHP和bash脚本都具有完全控制权。

如果我在当前目录(与PHP文件相同的目录)中运行shell脚本,那么它工作正常。但是,如果我尝试从/some/other/directory/shell.script运行shell脚本,那么它不起作用。这是为什么?

我试图chdir()到其他目录,但运行getcwd()后,它从来没有改变目录。

我也尝试了exec命令本身,它不起作用。 SHELL脚本

<?php error_reporting(E_ALL); ini_set('display_errors',1); 

echo "<h1>EDS Count Report</h1><p>"; 

$output=shell_exec('cd /app/script/catalog/ && ./EDScount_report.sh'); 
echo $output; 
?> 

内容:

+0

你确定没有安装CHROOT之类的软件吗? open_basedir也可能会限制文件系统的访问。 –

+0

在打开PHP标记后立即在您的文件顶部添加错误报告,例如'<?php error_reporting(E_ALL); ini_set('display_errors',1); '然后你的代码的其余部分,看看它是否产生任何东西。 –

+0

我在头文件中添加了它,但它仍然没有显示任何错误消息。当我尝试从命令行运行php文件时,出现以下错误: 'builder @ ae-prod-lxb101:/ build2/php/dev> ./phpfile.php4 ./phpfile.php4:line 1:语法错误附近的意想不到的令牌'''' ./phpfile.php4:第1行:'<?php error_reporting(E_ALL); ini_set('display_errors',1);'' – astra

回答

1

试试这个请

<?php 
$output=shell_exec('sh /path/to/otherdirectory/shellscript.sh'); 
echo $output; 
?> 

如果你确定,你可以访问dicertory,你也可以使用这样的:

<?php 
    $output=shell_exec('cd /path/to/otherdirectory/ && ./shellscript.sh'); 
    echo $output; 
    ?> 
+0

不幸的是 – astra

+0

为什么这下来投票?我似乎还不能解决这个问题。 – astra