从perl脚本调用unoconv时,设备的ioctl不合适

时间:2015-01-26 10:38:29

标签: perl postfix-mta document-conversion

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

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

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);
}

1 个答案:

答案 0 :(得分:0)

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.