3

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.

6
  • How long does the command take to run on the command line? Commented Feb 18, 2011 at 0:04
  • 1
    Try using the absolute path to tesseract. To find it out, run which tesseract from the command line. Then take that result and use that path in the shell_exec call... Commented Feb 18, 2011 at 0:05
  • @Orbling - I think about 10 seconds. Commented Feb 18, 2011 at 0:05
  • @bryan sammon: It takes longer than that to execute the PHP script? [Alter to the absolute path as recommended by ircmaxell first] Commented Feb 18, 2011 at 0:08
  • I just altered the path and it takes the same amount of time and still doesnt write the text_file. You think it may be leaving it in a different directory? Commented Feb 18, 2011 at 0:10

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Just got back to see someone answered. This was def the simplest way to do this. I had already started on this before you answered and its going to be by far the best solution. Thanks for your help.
1

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.