从perl脚本调用unocconv时设备的IOCTL不合适



每次收到指定域的电子邮件时,我都会从后缀电子邮件服务器触发一个perl脚本。perl脚本基本上提取所有附件,然后调用unoconv将附件转换为PDF格式。

我目前正在使用始终具有相同附件的相同电子邮件测试脚本,并且我看到了随机行为。有时所有附件都会被转换,有时我在调用unoconv命令时收到错误"设备不合适的ioctl"错误,例如:

unoconv -f pdf -o /tmp/2151DC80-A545-11E4-880B-D7DC6512523E/ '/tmp/2151DC80-A545-11E4-880B-D7DC6512523E/attachments/21887524-A545-11E4-880B-D7DC6512523E-test.doc'

看起来像一些赛车条件问题或类似问题。可能是什么问题?

更新:问题似乎是 unoconv 有时会以浮点异常退出,但是文档已成功转换(我可以在 PDF 查看器中打开它)。此处是出现错误的函数的代码。现在的问题是在这种情况下如何进行。

################################################################################
#                       Convert attachments to PDF                             #
################################################################################
sub convertAttachments() {
  $logger->info("converting attachments");
  mkdir  $email_converted_attachment_dir;
  opendir(DIR, $email_attachment_dir) or die $!;
    while (my $file = readdir(DIR)) {
        next if ($file =~ m/^./);
        $logger->info("Converting attachment: ".$email_attachment_dir.$file);
        $conv_result = "unoconv -v -T 10 -f pdf -o ".$email_converted_attachment_dir." '".$email_attachment_dir.$file."'";
        $logger->info("Running Command: ".$conv_result);
        system($conv_result) and die  "Can't launch unoconv: $!";
    }
  closedir(DIR);
}

man unoconv 说:

unoconv uses the LibreOffice’s UNO bindings for non-interactive
   conversion of documents and therefore needs an LibreOffice instance to
   communicate with. Therefore if it cannot find one, it will start its
   own instance for temporary usage. If desired, one can start a
   “listener” instance to use for subsequent connections or even for
   remote connections.

-T, --timeout
       When unoconv starts its own listener, try to connect to it for an
       amount of seconds before giving up. Increasing this may help when
       you receive random errors caused by the listener not being ready to
       accept conversion jobs.

相关内容

  • 没有找到相关文章

最新更新