我在 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 (php index.php
),输出是
<html>
<body>
13.00
is the result</body>
</html>
那么,结果在哪里丢失了?
编辑: 来自firefox的网页源码是
<html>
<body>
is the result</body>
</html>
编辑:已解决。 bash 脚本使用“~”,当脚本从网络服务器运行时,它会扩展到错误的目录。
最佳答案
exec 函数“仅”返回 stdout 的内容,这就是为什么您可能会错过错误消息的原因。
但是你可以redirect stderr到标准输出,例如通过
$res = shell_exec("/var/www/html/run.sh 2>&1");
关于php - HTML 不显示字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34451977/