Shell PHP 命令和浏览器不返回相同的输出


Shell PHP command and browser don't return the same output

这是我的脚本

测试.php

function doc2text($filename){
    $name = pathinfo($filename,PATHINFO_FILENAME);
    $count = exec('abiword --to=txt '.$filename.' && wc -w classes/'.$name.'.txt');
    $count = explode(" ",$count);
    var_dump($count);
    return $count[0];
}
echo doc2text('classes/demo.pdf');

当我在命令行中运行此脚本时,如下所示:

php test.php

var_dump输出正常:

array(2) {
  [0]=>
  string(4) "1663"
  [1]=>
  string(16) "classes/demo.txt"
}

但是当我在浏览器上运行同一页面时,数组为空:

array(1) { [0]=> string(0) "" }

这真的很奇怪...有什么线索为什么这样做吗?

abiword可能不在Web服务器环境的路径中。 尝试: /path/to/abiword . 此外,$filename需要位于正在运行的 PHP 脚本的目录中,或者您需要指定路径。

同时使用错误报告:

error_reporting(E_ALL);
ini_set('display_errors', '1');