PHP shell 执行命令

PHP shell exec command

我正在使用 windows 应用程序 tesseract,长话短说,这是一个通过命令运行的 OCR 应用程序。

安装应用程序后,我使用命令进行测试并使用此行工作正常:

tesseract text.png out

它实际上是获取图像并输出到文本文件out.txt

我什至更改了目录并且可以从任何地方访问。

现在使用php时出现问题,我使用的代码如下:

echo exec("tesseract text.png out 2>&1", $output);
var_dump($output);

这次不是获取文件,而是说无法识别 tesseract!

这是输出:

operable program or batch file.
C:\wamp64\www\prestashop\ocr\ocr.php:12:
array (size=4)
  0 => string '' (length=0)
  1 => string 'C:\wamp64\www\prestashop\ocr>tesseract text.png out'    (length=51)
  2 => string ''tesseract' is not recognized as an internal or external command,' (length=65)
  3 => string 'operable program or batch file.' (length=31)

谁能帮帮我!?

谢谢

我有答案。我不知道为什么,但我必须重新启动电脑才能使其与 PHP

一起工作

似乎 windows 环境变量 PATH 没有设置。

尝试重置PATH

echo exec("PATH %PATH% && tesseract text.png out 2>&1", $output);
var_dump($output);

或从父会话中设置 PATH

echo exec("PATH ".getenv('PATH')." && tesseract text.png out 2>&1", $output);
var_dump($output);

希望这会有所帮助