0

每次收到指定域的电子邮件时,我都会从 postfix 电子邮件服务器触发 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);
}
4

1 回答 1

0

人 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.
于 2015-01-26T11:01:22.057 回答