简体   繁体   中英

Grab output of a command lines in linux bash unusual result

#!/bin/bash
output=$(compare -subimage-search -metric mae large_image.png item.png result.png)
echo "Output is: $output"

It displays like something like this:

7216.53 (0.110117) @ 6,4
Output is:

But I am expecting something like this

Output is: 7216.53 (0.110117) @ 6,4

It seems to me that compare(imagemagick) is using other print line command other than 'print' or 'echo'

I have no problem with other command line such as:

output=$(date)
echo "output is: $output"

This will yield to:

output is: Fri Nov 22 01:02:07 PHT 2013

Probably compare is writing to stderr instead of stdout

Try this command:

output=$(compare -subimage-search -metric mae large_image.png item.png result.png 2>&1)
echo "Output is: $output"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM