change exit status to 0 even with all IF failed

Started by Harald, January 16, 2018, 12:52:59 PM

Previous topic - Next topic

Harald

Hi Phil,
I try to avoid overwriting my images on each run of my sync application (Syncovery) where the Exiftool commands run as pre-job batch file.

So I spent some hours and found a working solution setting two tags as "flags" for processed images. This works flawlessly now. The problem is that EXIFTOOL returns exit status "1" if ALL if conditions failed. With the batch file exiting with "1" Syncovery does not proceed its job.

So my question is: is there a way to change this default behaviour and have Exiftool exit with "1" only if a real error occurs?

This is my code: it is certainly not a perfect solution but at least it works. :)

EXIFTOOL -r -P -overwrite_original_in_place -EXT jpg -IF "not defined $IPTC:EditStatus" -d %%Y-%%m "-iptc:caption-abstract <WebCaptionTag" -IPTC:EditStatus='processed' .
EXIFTOOL -r -P -overwrite_original_in_place -EXT jpg -IF "not defined $IPTC:jobID" -d %%Y-%%m "-description<WebCaptionTag" -IPTC:jobID='processed' .

Thanks a lot in advance for your help.

Phil Harvey

Unfortunately this is a design feature.  The idea is that a script can use the return status to tell if the exiftool -if condition succeeded or not.

You're saying that you can't continue with a script if one of the commands returns an error status?  I find this odd.

- Phil

Edit:  Instead of setting flags in the metadata, why not move the file to a different directory if it was processed?
...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 ($).

Harald

Thanks for the quick reply, Phil.
The sync software stops when the pre-job returns an error and you would have to manually proceed, which makes sense.
I just realised that it would not have been such a big deal. If there is no new file anyway, no sync needed. Of course the problem is that if any real problem occurs with the Exiftool command I would not notice.
But now my challenge is that for some reason Exiftool returns "1" even when there is a new image.

This is my batch file:
E:
cd\SyncToGooglePhotos
EXIFTOOL -r -P -overwrite_original_in_place -EXT jpg -IF "not defined $IPTC:EditStatus" -d %%Y-%%m "-iptc:caption-abstract <WebCaptionTag" -IPTC:EditStatus='processed' . > log.txt
EXIFTOOL -r -P -v1 -overwrite_original_in_place -EXT jpg -IF "not defined $IPTC:jobID" -d %%Y-%%m "-description<WebCaptionTag" -IPTC:jobID='processed' . >> log.txt

The file log.txt is attached. Any ideas?

Phil Harvey

ExifTool will exit with "1" if an error occurred or if all files failed the -if condition.

If this isn't what is happening, then it needs to be fixed.

- 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 ($).

Harald

So how do I fix it?
Any way to see what causes the error? As you can see from the log file with -v1 option, there were two files updated. Thus it is not the case that all IF-clauses fail. And there was no other message output reporting an error.
Sorry if I am missing something obvious.

Harald

And a question that should have been asked before, yet I could not find it: do you know consultants who offer exiftool support as a paid service? Sometimes it is worthwhile to pay for somebody rather than spend hours poking around in the dark ...

Phil Harvey

Hi Harald,

Quote from: Harald on January 17, 2018, 11:54:51 AM
So how do I fix it?

You don't.  I do.  But I need enough information to reproduce the problem here.  I have seen your log file, but I don't even know what command was used to generate this, nor what was the exit status of the command.

Quote from: Harald on January 17, 2018, 12:04:21 PM
And a question that should have been asked before, yet I could not find it: do you know consultants who offer exiftool support as a paid service? Sometimes it is worthwhile to pay for somebody rather than spend hours poking around in the dark ...

I don't know of anyone like this.  I'll help as much as I can, and you're free to donate money 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 ($).

Hayo Baan

Quote from: Phil Harvey on January 17, 2018, 01:16:43 PM
Quote from: Harald on January 17, 2018, 12:04:21 PM
And a question that should have been asked before, yet I could not find it: do you know consultants who offer exiftool support as a paid service? Sometimes it is worthwhile to pay for somebody rather than spend hours poking around in the dark ...

I don't know of anyone like this.  I'll help as much as I can, and you're free to donate money if you want.

Well, if you really need something developed especially for you, I might be of (paid) service. But I think this forum and its top contributors will suffice in most, if not all, cases :)
Hayo Baan – Photography
Web: www.hayobaan.nl

Harald

Hi Phil and Hayo,

thanks Phil.
So you need to know the command that created the log?
It was mentioned in my post. It is a batch file that is:
-------
E:
cd\SyncToGooglePhotos
EXIFTOOL -r -P -overwrite_original_in_place -EXT jpg -IF "not defined $IPTC:EditStatus" -d %%Y-%%m "-iptc:caption-abstract <WebCaptionTag" -IPTC:EditStatus='processed' . > log.txt
EXIFTOOL -r -P -v1 -overwrite_original_in_place -EXT jpg -IF "not defined $IPTC:jobID" -d %%Y-%%m "-description<WebCaptionTag" -IPTC:jobID='processed' . >> log.txt
-------

How do I see the exit code?
Problem is that the batch file gets started from Syncovery as a "pre-job". This means the batch file is started from another application. For that reason the dos command prompt window closes immediately after Exiftool finished.
I am happy to run the commands in other variations to give more details if you tell me how to.

And of course I did donate in the past and keep doing so as your tool is amazing and so is your support. :)
As many people post: there is hardly any paid software where you get such a great support.

And Hayo: thanks a lot for your offer. My idea is to use consultancy in the form of Skype meetings with screen sharing to quickly track down errors or find the proper syntax. I have enough programming background and Exiftool experience to understand quickly if someone points me to the right direction. So it would typically be 30 mins to 1 hr sessions at most.
I will send you a message to exchange our email addresses and then we can discuss the details.


Phil Harvey

I did some googling and it seems that this command can be used in cmd.exe shell to show the exit status of a command:

echo %errorlevel%

If this works, try running the exiftool commands manually and seeing what the exit codes are.

- 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 ($).

Harald

I did another test and then run the command. Error code is 1.
find the log file with -v1 attached. It shows in the last line that one image file was updated. And there is no line with "error". so it should have returned "0", right?

Phil Harvey

What is the command you used for this output?

- 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 ($).

Harald

E:\SyncToGooglePhotos>EXIFTOOL -v1 -r -P -overwrite_original_in_place -EXT jpg -
IF "not defined $IPTC:EditStatus" -d %Y-%m "-iptc:caption-abstract <WebCaptionTa
g" -IPTC:EditStatus='processed' . > processed.txt 2>> log.txt

E:\SyncToGooglePhotos>echo %errorlevel%

Phil Harvey

OK, thanks.  I can reproduce this.

You are correct.  ExifTool should be returning 0 here.  This will be fixed for the next release (10.77).

- 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 ($).

Phil Harvey

I think at the same time I will set the exit status to 2 if all files failed the -if condition.  This will allow you distinguish this from the case where an error occurred.

- 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 ($).