簡體   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