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?

Mohamed Khamis
  • 7,731
  • 10
  • 38
  • 58
  • 1
    `sudo` at the very least needs a password, no? – nickb Jul 27 '12 at 16:44
  • 1
    Are you running the PHP file through `sudo`, so it gets the permissions you used before? – halfer Jul 27 '12 at 16:47
  • It looks like there's a couple helpful hints in the comments of the `shell_exec` [reference page](http://php.net/manual/en/function.shell-exec.php) 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. – Gordon Bailey Jul 27 '12 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. – Gordon Bailey Jul 27 '12 at 16:49

1 Answers1

2

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

shell_exec("file='document1.pdf' ./shell.sh")
Igor Chubin
  • 61,765
  • 13
  • 122
  • 144