我正在尝试在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设置。

当php执行脚本时,它没有shell安装程序,并以webserver用户帐户运行。执行时:

  • 确保您具有完整的文件路径,swipl是不够的,它应该是/path/to/swipl
  • 确保 Web服务器进程具有足够的访问权限以获取所需的一切。
  • 关于php - 无法在PHP中运行bash脚本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12543064/

    10-09 08:43
    查看更多