exit codes in batch processing mode

Started by ugh_bough, September 02, 2016, 06:23:32 AM

Previous topic - Next topic

ugh_bough

Hi,

I'm using exiftool to process photos in a database. In particular, I'd like to

- check if exifdata is 'correct' before a new image enters the database (using a 'dummy write' to the file)
- update exifdata from database (writing to the file)

In such cases, I'd like to react to write errors by trying to repair exif data and retry to write, and -- if not successful -- exclude a photo from the database.

In the script I use the batch processing capabilities of exiftool. However, I did not find a documented way how exiftool reports success -- other than status messages and {ready}-messages.

I feel that status messages could be subject to change in the future and evaluating these with e.g. regular expressions might not be a good idea. Is there a programmatic, reliable, consistent, future-proof way to check whether the last executed command was successful, like e.g. an 'error code' or similar?

Thanks in advance
ugh_bough

Phil Harvey

The exit code is documented in the DIAGNOSTICS section of the application documentation.  (I know, this isn't very intuitive, but it is the traditional place for this information in Unix documentation.)

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

ugh_bough

Thank you for the quick response!

In batch processing mode (i.e. when using the -stay_open True option) there seems to be no way to test success for each individual file.

I was hoping that there exists e.g. a special tag like -exitCode which, when given in an -executed command, makes exiftool provide the exitCode that would have occured if the -executed command was the only command. (Output in the regular format, like a colon-separated line or a table cell in -T mode.)

Without individual tests exiftool must be called multiple times (once for each file), which is not desirable when processing thousands of photos :'(

Regards
    ugh_bough

ugh_bough

Hello again,

after digging into the source code I can seen that a special tag like -exitCode might not be a good idea. So here is another idea/suggestion/feature request ;)

At the end of the command loop the variable $rtnVal is updated just after status messages (like "1 files updated") are written. Would this be an appropriate place to output an additional status message for the exitCode of the current command?

(Of course, this additional status message would have to be optional and should be the last status message -- such that it directly precedes any {ready}-message in "-stay_open True"-mode).

Best regards
    ugh_bough

Phil Harvey

It should be easy enough to figure out the exit code by looking at the stderr output.  If there is an error message, then the exit code would also indicated an error.  You can specifically request the Error tag if you want.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

ugh_bough

Hi.

Thanks again for your kind support.

I resorted to redirecting stdout and stderr to the same named pipe:
Since errors are printed before the {ready} message I can check if the output contains error messages.

Cheers
    ugh_bough