1

On the terminal, I run this successfully within the web application's directory:

pdftohtml -c -noframes "documents/document1.pdf"

Now I want to do this through PHP, so I wrote a shell.sh file that looks like this:

sudo pdftohtml -c -noframes "documents/$file"
exit 0

Then I wrote this in php:

$output = shell_exec("file='document1.pdf' shell.sh");

It doesn't work, I expect to see html files generated, but I get some empty html files..since the command worked fine through the terminal, then I think the problem is in the way I execute it from php

echoing $output doesn't show anything.. what do I do wrong?

4
  • 1
    sudo at the very least needs a password, no? Commented Jul 27, 2012 at 16:44
  • 1
    Are you running the PHP file through sudo, so it gets the permissions you used before? Commented Jul 27, 2012 at 16:47
  • It looks like there's a couple helpful hints in the comments of the shell_exec reference page specifically what was mentioned about sudo needing a password and also the possibility that you might need to redirect stderr to stdout (2>&1) to get any output. Commented Jul 27, 2012 at 16:47
  • try redirecting stderr to /dev/null and see if you still get output pdftohtml 2>/dev/null -c -noframes "documents/document1.pdf". If you don't see anything then it means that the output is written to stderr and you'll need to redirect stderr to stdout for shell_exec to give any output. Commented Jul 27, 2012 at 16:49

1 Answer 1

2

You need specify path to the script (or ./ if it is the current directory):

shell_exec("file='document1.pdf' ./shell.sh")
Sign up to request clarification or add additional context in comments.

2 Comments

This gives me a shell.sh: command not found I should get an html file per page in document1.pdf, I only get a single empty one
run file='document1.pdf' ./shell.sh

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.