Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP shell_exec() - having problems running command

Tags:

php

exec

Im new to php shell commands so please bear with me. I am trying to run the shell_exec() command on my server. I am trying the below php code:

$output = shell_exec('tesseract picture.tif text_file -l eng');
echo "done";

I have the picture.tif in the same directory as the php file. In my shell I can run this without a problem.

It takes a while to run the code, then it doesnt make the text_file like it does when I run it in command prompt.

like image 220
bryan sammon Avatar asked Sep 12 '26 20:09

bryan sammon


2 Answers

Per your comment:

Should I write a loop in shell instead?

You can write a very simple shell script to run the command in a loop. Create the script file first:

touch myscript.sh

Make the script executable:

chmod 700 myscript.sh

Then open it with a text editor such as vim and add this:

for ((  i = 0 ;  i <= 5;  i++  ))
do
  tesseract picture.tif text_file -l eng
done

Thats the very basics of it (not sure what else you need), but that syntax should help get you started. To run the script, do this if you're in the same directory as the script:

./myscript.sh

Or specify the full path to run it from anywhere:

/path/to/mydir/myscript.sh
like image 72
Banjer Avatar answered Sep 15 '26 09:09

Banjer


Could this be a permissions issue? My guess is that PHP isn't running with the same permissions that you do when you execute the command directly from the command prompt. What OS are you running on?

like image 40
Jeremy Avatar answered Sep 15 '26 09:09

Jeremy