ImageMagick - 抑制警告消息

时间:2012-06-19 14:53:55

标签: imagemagick cmd

我使用以下内容来获取PDF文档中的总页数:

identify -format %n test.pdf

然后我删除所有非数字字符以从响应中获取单个整数。

有时会产生以下错误,导致上述错误产生错误的页数,因为它们是与响应中的页面无关的其他数字。

   **** Warning: Fonts with Subtype = /TrueType should be embedded.
             The following fonts were not embedded:
                    Arial
                    Arial,Bold
                    Arial,Italic
                    Times New Roman

    **** This file had errors that were repaired or ignored.
    **** The file was produced by:
    **** >>>> Microsoft« Office Word 2007 <<<<
    **** Please notify the author of the software that produced this
    **** file that it does not conform to Adobe's published PDF
    **** specification.

    9

“9”是文档中的页数。

如何处理警告消息,我尝试使用“-quiet”标志,但仍然会生成消息。

2 个答案:

答案 0 :(得分:2)

警告发送到stderr,因此简单的输出重定向就可以解决问题:

 identify -format %n test.pdf 2>/dev/null

答案 1 :(得分:1)

从identify的手册页中

  

-安静地禁止显示所有警告消息

因此,您的命令应如下所示,以禁止显示警告消息:

identify -quiet -format %n test.pdf
相关问题