【问题标题】:php exec tesseract outputs empty arrayphp exec tesseract 输出空数组
【发布时间】:2014-03-31 23:22:22
【问题描述】:

我在 Windows 7 上安装了 tesseract v3.01。我在环境变量中添加了 tesseract 路径。在 cmd 窗口中输入以下命令后,我获得了正确的输出:“tesseract test.tif test”。

当我尝试使用以下脚本在 php 中获得相同的结果时,我得到一个空数组并且没有生成文件:

<?php

try {
    exec("tesseract.exe test.tif test", $msg);
    var_export($msg);
} catch (Exception $e) {
    echo $e;
}

?>

有什么线索吗?

提前致谢!

【问题讨论】:

    标签: php exec tesseract


    【解决方案1】:
    <?php
    
    try {
        $msg = array(); // TRY THIS 
        exec("tesseract.exe test.tif test", $msg);
        var_export($msg);
    } catch (Exception $e) {
        echo $e;
    }
    
    ?>
    

    【讨论】:

    • 结果我仍然有相同的空数组:(
    • 所以我再次测试......在将 tesseract 文件复制到 php 脚本的文件夹后它运行良好。我尝试使用 putenv()。正方体在路径环境变量中声明...
    • 好吧,也许是因为权限。试试这个 exec("tesseract.exe test.tif test 2>&1", $msg);
    【解决方案2】:

    为什么不尝试指定 tesseract 的完整路径?

    不知道如何在 Windows 上执行此操作,但在 mac 终端上,我输入 which tesseract,它会找到 tesseract 的完整路径。然后,您可以在 exec 命令中输入完整路径,在我的情况下为 /usr/local/bin/tesseract

    try {
        $msg = array();
        exec("/usr/local/bin/tesseract test.tif test", $msg);
        var_export($msg);
    } catch (Exception $e) {
        echo $e;
    }
    

    【讨论】:

      猜你喜欢
      • 2014-02-10
      • 2014-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多