首页 > 解决方案 > 使用 php 返回码 77 执行系统命令

问题描述

我正在尝试使用 libreoffice 将 word 文档转换为 pdf。该命令在终端中运行良好,但在我用 php 编写的应用程序的控制器中使用shell_exec(),否则exec()它不起作用。exec()的 return_var 是 77,我认为这意味着:

错误的文件描述符

任何建议都会受到高度赞赏。

标签: phplibreofficeshell-exec

解决方案


我添加了这个命令选项来修复它:

 -env:UserInstallation=file:///tmp/test

我的代码是:

  $command = "{$bin} -env:UserInstallation=file:///tmp/test --headless --convert-to pdf:writer_pdf_Export --outdir  '{$pdfTmpDir}' '{$path}' 2>&1";
  exec($command, $output, $code);

推荐阅读