PHP shell exec command


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);

希望这将有助于