Page 1 of 1

Assigning compare output to a variable

Posted: 2015-09-24T05:48:26-07:00
by ninaw
I'm running a script to compare images but want the script to do things based on the level of difference. How on earth so I assign the output of the compare command to a variable, and if possible convert it to an integer (rounded or truncated, it doesn't really matter)? So far I have tried various syntax for treating it like a normal operation. None have worked.
I'm running a Linux terminal window on Ubuntu 14.04

I have tried
difference=$((compare -metric PSNR file1.png file2.png diff.png))
and
difference=`compare -metric PSNR file1.png file2.png diff.png`
and various others.

Re: Assigning compare output to a variable

Posted: 2015-09-24T07:40:29-07:00
by snibgo
The text is written to stderr, not stdout. Put

Code: Select all

2>&1
before the close backtick.

Re: Assigning compare output to a variable

Posted: 2015-09-24T08:26:23-07:00
by ninaw
Many thanks. That has solved the problem, and fortunately before I pulled all my hair out.