"Mogrify" error handling in Windows batch

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
wallywalters
Posts: 1
Joined: 2017-02-14T01:20:19-07:00
Authentication code: 1151

"Mogrify" error handling in Windows batch

Post by wallywalters »

I'm writing a Windows batch file to change folders full of TIF files to JPG and want it to go to an error-handling label if the TIF file is invalid. The relevant code is essentially

Code: Select all

  mogrify.exe -format jpg "%1"    
  if not %ERRORLEVEL%==0 goto :BAD_FILE 
but even when I run it on test TIFs designed to fail the test, it returns an errorlevel of 0, so I can't brandh to the error reporting subroutine. How can I make Mogrify return proper error codes? Thanks.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: "Mogrify" error handling in Windows batch

Post by snibgo »

wallywalters wrote:if not %ERRORLEVEL%==0
That's not how to do it. I suggest you read up on Windows BAT scripts. Try:

Code: Select all

if ERRORLEVEL 1
snibgo's IM pages: im.snibgo.com
Post Reply