2015-12-24 11:18
浏览 94


I'm running lighttpd 1.4.35 on Debian 8.2. I have a very simple html file with php code (php5) which calls a bash script and prints the output:

    $res = shell_exec("/var/www/html/");
    echo $res . " is the result";

If that html file is called on firefox, the output is

 is the result

If I directly run php with that file (php index.php), the output is

 is the result</body>

So, where does the result get lost?

edit: The webpage source code from firefox is


 is the result</body>

edit: solved. bash script uses '~' which expands to wrong directory when the script is run from webserver.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dstbp22002 2015-12-24 11:37

    The exec functions "only" return the contents of stdout, which is why you might miss an error message.
    But you can redirect stderr to stdout, e.g. via

    $res = shell_exec("/var/www/html/ 2>&1");
    解决 无用
    打赏 举报

相关推荐 更多相似问题