3

I'm trying to convert word documents to PDF, via the commandline using unoconv via PHP.

I'm using the Symfony Process Component to run the command via the command line.

public function run()
{
    $cmd = 'unoconv --listener & unoconv ' . $this->path;

    //Tested this to check for permissions and this worked.
    //$cmd = 'touch /vagrant/public/testfile.pdf'; 

    $process = new Process($cmd);  
    $process->run();

    return $process->getOutput();
}

This yields no output, and doesn't convert the file. However if I echo the $cmd and paste it into the CLI it converts the file as expected and logs output as it goes.

Any ideas what could be the problem?

Edit: I've since tried: calling mustRun() & start() methods on the symfony class.

mustRun() gives the following error:

"The command '//command//' failed. Exit Code: 251(Unknown error) Output: ================ Error Output: ================

After adding the log code as suggested by Diego Ferri, I get Error: Unable to connect or start own listener. Aborting. in the log file; but I can't find much online that's helpful for that.

luchaninov
  • 6,792
  • 6
  • 60
  • 75
Kiee
  • 10,661
  • 8
  • 31
  • 56
  • Try, in this order: (1) specifying the full path to unoconv, (2) escaping the path with `escapeshellarg`, and (3) escaping the `&`. A full command might look like: `/usr/bin/unoconv --listener \& unoconv ' . escapeshellarg($this->path);` – bishop Sep 03 '15 at 12:08
  • Forgot to mention, i've already tried #1. #2 and #3 no change. – Kiee Sep 03 '15 at 12:51
  • Is the error output literal? Or did you substitute `'//command//'` for the actual command shown in the error? At any rate, based on the [man page](http://linux.die.net/man/1/unoconv), there may be a problem using Process with a background process. Try the one-shot version: `$cmd = sprintf('/usr/bin/unoconv -f pdf %s', escapeshellcmd($this->path));`. – bishop Sep 03 '15 at 13:23

1 Answers1

0

Please read this section but also check the troubleshooting section.

It is possible that the shell is missing some important environment variables for unoconv/LibreOffice to work properly (PATH, HOME, ...). And it is recommended you call the LibreOffice python binary with unoconv instead of leaving it up to unoconv to determine the location of LibreOffice and python.

Dag Wieers
  • 1,663
  • 13
  • 11