【问题标题】:HTML not showing charactersHTML不显示字符
【发布时间】:2016-03-30 20:24:51
【问题描述】:

我在 Debian 8.2 上运行 lighttpd 1.4.35。我有一个非常简单的带有 php 代码 (php5) 的 html 文件,它调用 bash 脚本并打印输出:

<html>
<body>
<?php
    $res = shell_exec("/var/www/html/run.sh");
    echo $res . " is the result";
?>
</body>
</html>

如果在 firefox 上调用该 html 文件,则输出为

 is the result

如果我直接使用该文件 (php index.php) 运行 php,则输出为

<html>
<body>
13.00
 is the result</body>
</html>

那么,结果在哪里丢失了?


编辑: 来自firefox的网页源代码是

<html>
<body>

 is the result</body>
</html>

编辑:已解决。 bash 脚本使用“~”,当脚本从网络服务器运行时,它会扩展到错误的目录。

【问题讨论】:

  • 尝试使用$res = shell_exec("sh /var/www/html/run.sh");运行
  • exec 函数“仅”返回标准输出的内容。将 stderr 重定向到 stdout 时是否收到错误消息? $res = shell_exec("/var/www/html/run.sh 2&gt;&amp;1");
  • @VolkerK - 就是这样,谢谢。 shell脚本使用'~',当直接在bash中运行php时,它被扩展为正确的目录,但当web服务器运行脚本时,它指向错误的目录。愚蠢的我;)
  • 比预期的要简单 ;-) 那我会回答的。

标签: php html firefox lighttpd


【解决方案1】:
如果您处于安全模式

shell_exec 不会运行,这可能是问题

【讨论】:

    【解决方案2】:

    exec 函数“仅”返回标准输出的内容,这就是您可能会错过错误消息的原因。
    但是你可以redirect stderr 到标准输出,例如通过

    $res = shell_exec("/var/www/html/run.sh 2>&1");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-14
      • 1970-01-01
      • 1970-01-01
      • 2011-09-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多