Option -metric outputs to STDERR

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
sven
Posts: 27
Joined: 2003-10-02T02:21:38-07:00

Option -metric outputs to STDERR

Post by sven »

Hi magick,

the documentation says (http://www.imagemagick.org/script/comma ... php#metric) that the option -metric AE outputs to STDERR. I wonder, why it does not output to STDOUT. Well, of course it's the error count of the number of different pixels, but it makes it difficult to only read the number of different pixel and not other error information.

Is there any way to change the output to STDOUT (only for this option) or to output the information in a structered way in order to ignore other error outputs?

Kind regards,
Sven
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Option -metric outputs to STDERR

Post by magick »

We send the metric to stderr because the user may want to send the difference image to stdout. Something like this:
  • compare -metric pae reference.png image.png png:- | identify -verbose -
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Option -metric outputs to STDERR

Post by magick »

There is at least 10 different places in ImageMagick that writes text info to stderr and any image to stdout. Its been this way for quite sometime (other than the occasional bug) and we intend on keeping it that way. If we change it now it would most likely break a lot of existing scripts and bring ire from numerous users.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Option -metric outputs to STDERR

Post by anthony »

Typically what you would do is junk the image output and then redirect stderr to either stdout or a file using your command line shell.

For example

Code: Select all

   convert -metric AE image1 image2 null: 2>metric.txt
or

Code: Select all

     result=`convert -metric AE image1 image2 null: 2>&1`
The 2> and 2>&1 are NOT Imagemagick syntax, but Bourne or BASH shell syntax, if you are on a UNIX-like environment.

see the still rough notes in IM Examples Compare
http://imagemagick.org/Usage/compare/#compare
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply