繁体   English   中英

PHP shell exec命令

[英]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)

任何人都可以帮助我!?

谢谢

我有答案。 我不知道为什么,但我必须重新启动PC才能使用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);

希望这会有所帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM