Search code examples
phplinuxshelllibreoffice

Error on executing libreoffice command using shell_exec()


Code:

shell_exec('libreoffice --convert-to pdf `'.$my_file.'` --headless');

I have tried this too

shell_exec('libreoffice --convert-to pdf `'.$my_file'` --headless > /dev/null');

Error on the server while executing above:

Output:sh: /my_files/my_file.doc: cannot execute binary file

Note: All other commands of linux working fine with shell_exec() just libreoffice command not working. And on linux terminal the libreoffice command working fine just not working using PHP.


Solution

  • You're using backticks, which tells the subshell to run that command and use its output in its place. Use double quotes instead, and it will work far more often.