Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question
    
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 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 at 11:59

2 Answers 2

up vote 2 down vote accepted

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
share|improve this answer
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
share|improve this answer
    
keeps printing it into console, but just the compare command return value is printed –  Stefan Sprenger Apr 26 at 11:50
    
Try the command suggested by Gnouc in above piece of code. –  Mandar Shinde Apr 26 at 11:53
    
when i have enough rep i will vote you up .. thx –  Stefan Sprenger Apr 26 at 11:58
    
My pleasure :-) –  Mandar Shinde Apr 26 at 11:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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