php exec command not running?
-
23-12-2019 - |
Question
I have a PHP file Executing a shell command for a tool called PDFTK.
The command works fine when I run it directly from the command line but through the PHP script it self, it does not and doesn't throw an error.
The command i am running is:
$WshShell = new COM("WScript.Shell");
$WshShell->Exec("pdftk Template.pdf fill_form 1406822788.fdf output test2.pdf");
This takes the .fdf data and puts it into the template pdf and then creates the outout of test2.pdf.
Again, works fine when ran directly through the command line.
Any ideas on what I can try to get this to run?
Solution
Check the return of the method Exec, or try:
exec("pdftk Template.pdf fill_form 1406822788.fdf output test2.pdf");
OTHER TIPS
This may be because your webserver process user does not have privileges to do so. or
Add 2>&1 to the end of your command to redirect errors from stderr to stdout.
See here for further clarification
It could be many things, but first thing to do is specify the full path to pdftk binary. Chances are, the PHP environment (e.g. apache, nginx, etc) does not have the same PATH variables as your user account.