2

I tried to put the output of my program into a text file. It appends the echo commands to the file properly, but the imagemagick "compare" command is not appended to the file. It just STOUD's the "PSNR value", which is returned by compare method into terminal.

Is there a way to append this commands output to the textfile too? Also if I call my script just with "./script.sh > test.txt" it doesn't print anything more than the echos to file and compare results to terminal.

Here's a part of my code:

ls images/toconvert/ > lsout.txt

while read LINE
do
    echo ====================== $LINE ==================== >> psnrdiff.txt
    echo Jpeg2000 >>  psnrdiff.txt
    compare -metric PSNR images/toconvert/$LINE images/converted/$LINE.jp2 images/psnrDiffs/$LINE.jp2.png >> psnrdiff.txt
done < lsout.txt
  • Your script is overly complicated and will break on some “weird” file names. Write for x in images/toconvert/*; do … compare -metric PSNR "$x" "images/converted/${x##*/}.jp2" "images/converted/${x##*/}.jp2.png"; done – Gilles Apr 26 '14 at 23:23
  • i differ between three types .. i mentioned before it's just a "part" of my code and not even this part is in the current code form, but thanks – Stefan Sprenger Apr 28 '14 at 11:59
  • 1
    funny it's exactly the script I was trying to make too. same issue. – v.oddou Jan 17 '18 at 9:38
3

Various imagemagick command output to STDERR instead of STDOUT.

You can redirect STDERR to STDOUT to capture the output:

compare -metric PSNR .... >> psnrdiff.txt 2>&1
  • very weirdly in my case it creates a 144MB file if I do that. (every pixel in a PPM-like format is enumerated in there) – v.oddou Jan 17 '18 at 9:40
1
ls images/toconvert/ > file.txt 
while read LINE
do
    echo ====================== $LINE ==================== >> psnrdiff.txt
    echo Jpeg2000 >>  psnrdiff.txt
    compare -metric PSNR "images/toconvert/$LINE" "images/converted/$LINE.jp2" "images/psnrDiffs/$LINE.jp2.png" >> psnrdiff.txt
done < file.txt
  • keeps printing it into console, but just the compare command return value is printed – Stefan Sprenger Apr 26 '14 at 11:50
  • Try the command suggested by Gnouc in above piece of code. – Mandar Shinde Apr 26 '14 at 11:53
  • when i have enough rep i will vote you up .. thx – Stefan Sprenger Apr 26 '14 at 11:58
  • My pleasure :-) – Mandar Shinde Apr 26 '14 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.