Identify from command line - need help

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
michaelpe
Posts: 2
Joined: 2012-11-01T06:58:27-07:00
Authentication code: 67789

Identify from command line - need help

Post by michaelpe »

Hello,
I'm trying to detect corrupted JPEG files. I'm running the identify utility using the command line. The option is -verbose. Everything works well: I actually receive
identify.exe: Corrupt JPEG data: premature end of data segment ....
But, I can't pick up this string for the further processing. Standard redirection to text file
identify -verbose file.jpeg > result.txt
prints into a file the whole verbose information, except the error. The error is printed out only to command line.
So if I want to run a batch processing of 100 files and detect how many files were corrupted, I can't do it. Unless I'm missing something...
Any suggestions?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Identify from command line - need help

Post by fmw42 »

try using -quiet -regard-warnings in an if statement, so that you can print out only some message you want.

see
http://www.imagemagick.org/Usage/basics/#controls

try something like this

infile="someimage.jpg"
convert -quiet -regard-warnings $infile null: ||
echo "--- FILE $infile IS NO GOOD ---"

See if that traps it cleaner. You can log the message to a file if you want also. I wrote the result if OK to null: (no image), but you can write it to some other file and add other commands after reading the file, if you want.


PS. This was on unix. I am not sure how to do the conditional on Windows. So see http://www.imagemagick.org/Usage/windows/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Identify from command line - need help

Post by snibgo »

The error is probably sent to stderr, which is channel 2. Pick it up with:

identify -verbose file.jpg 2>result.txt
snibgo's IM pages: im.snibgo.com
michaelpe
Posts: 2
Joined: 2012-11-01T06:58:27-07:00
Authentication code: 67789

Re: Identify from command line - need help

Post by michaelpe »

Thank you, guys, that was very helpful.
Post Reply