我試圖在PHP中運行bash腳本,但無法運行它。 php -v無法在PHP中運行bash腳本
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」 – Robbie
將'$ cmd'改爲'/www/var/pl/bash.sh 2> &1'。它仍然不會運行,但可能會給你一些關於它爲什麼沒有的見解。 – LSerni
你看到了什麼錯誤,如果有的話?我假設你的PHP沒有在安全模式下運行,並且exec命令沒有被禁止? – Basic