我試圖通過命令行使用unoconv通過PHP將word文檔轉換爲PDF。我使用Symfony Process Component通過命令行運行命令。使用unoconv通過Symfony組件轉換DOC爲PDF
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();
}
這就產生了無輸出,並且不轉換的文件。但是,如果我回顯$cmd
並將其粘貼到CLI中,它會按預期方式轉換文件,並隨着日誌輸出進行日誌輸出。
任何想法可能是什麼問題?
編輯: 我已經嘗試過,因爲:調用symfony的類mustRun()
& start()
方法。
mustRun()
提供了以下錯誤:
"The command '//command//' failed. Exit Code: 251(Unknown error) Output: ================ Error Output: ================
添加日誌代碼迭戈費裏的建議後,我得到的日誌文件Error: Unable to connect or start own listener. Aborting.
;但我無法在網上找到很多有用的信息。
按以下順序嘗試:(1)指定unoconv的完整路徑,(2)用'escapeshellarg'轉義路徑,(3)轉義'&'。完整的命令可能如下所示:'/ usr/bin/unoconv --listener \&unoconv'。 escapeshellarg($ this-> path);' – bishop
忘了提及,我已經試過#1。 #2和#3沒有變化。 – Kiee
錯誤輸出文字?或者你是否用錯誤中顯示的實際命令替換了'// //命令//''?無論如何,基於[手冊頁](http://linux.die.net/man/1/unoconv),使用Process與後臺進程可能存在問題。嘗試一次性版本:'$ cmd = sprintf('/ usr/bin/unoconv -f pdf%s',escapeshellcmd($ this-> path));'。 – bishop