【发布时间】:2012-09-14 14:47:14
【问题描述】:
我正在尝试在 PHP 中运行 bash 脚本,但无法运行它。 php -v
PHP 5.3.10-1ubuntu3.2 with Suhosin-Patch (cli) (built: Jun 13 2012 17:19:58)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
Ubuntu 12.04 LTS 64 位。
我的php代码:
$cmd='/www/var/pl/bash.sh';
$retval =-1;
exec( $cmd, $output ); //executing the exec function.
foreach( $output as $tmp )
{
echo "$tmp <br>";
};
bash.sh:
#!/bin/bash
swipl --quiet -s /var/www/pl/ples.pl -g "f(R, gel), writeln(R),open('/var/www/pl/in.txt',write, Stream),
write(Stream, (R)),
nl(Stream),
close(Stream)" -t halt.
我做错了什么?
我可以在 Linux 终端中运行 bash.sh。
【问题讨论】:
-
尝试在 shell 脚本前加上“bash” - 所以有“bash /www/var/pl/bash.sh”
-
将
$cmd更改为/www/var/pl/bash.sh 2>&1。它仍然无法运行,但可能会让您了解它为什么无法运行。 -
您看到了什么错误(如果有)?我假设你的 PHP 没有在安全模式下运行,并且 exec 命令没有被特别禁用?
标签: php linux bash swi-prolog