Error Opening Image for Writing When using -execute

Started by ghelfrich919, August 04, 2023, 09:53:44 PM

Previous topic - Next topic

ghelfrich919

I have a script that adds/updates date/time/GPS metadata to scanned photos in an iterative fashion using -execute.

When I run the script to update a photo, roughly 30% of the time I get an error when it tries to open the photo for editing.  See below for sample output.

    1 image files updated
    1 image files updated
Error opening (directory path)/2023-05-13-Lukas-01.jpg for writing
    0 image files updated
    1 files weren't updated due to errors
    1 image files updated
    1 image files updated

Anyone have any thoughts on what's going on here?  Like I said, it doesn't happen all the time.  And it doesn't always get this error at the same point in the execution of the script.

Also, can someone tell me the proper way to use the "$OK" userparm when using -execute possibly in an example? 

Additionally, using the -common_args option would possibly simply my script using -execute.  Once again, can someone tell me the proper way to use this possibly in an example?

Any help is greatly appreciated.

Gerry

StarGeek

Quote from: ghelfrich919 on August 04, 2023, 09:53:44 PMWhen I run the script to update a photo, roughly 30% of the time I get an error when it tries to open the photo for editing.  See below for sample output.

...
Error opening (directory path)/2023-05-13-Lukas-01.jpg for writing
    0 image files updated
    1 files weren't updated due to errors
...

Anyone have any thoughts on what's going on here?  Like I said, it doesn't happen all the time.  And it doesn't always get this error at the same point in the execution of the script.

It sounds like something is locking the file when exiftool tries to use it.  Anti-virus programs are a common answer. Or if it's on a NAS, something running in the background there could be locking it.  If I recall, on a Synology there's an always running background program which can do this. Or you might want to check the health of the drive.

QuoteAdditionally, using the -common_args option would possibly simply my script using -execute.  Once again, can someone tell me the proper way to use this possibly in an example?

Here's a very old and outdated command (created Nov 2014 according to my history) I used at one point. It would check Description for any sequences of two or more spaces and replace them with a single spaces.  Then it would do the same with Caption-Abstract.  These days there are much more efficient ways but it shows the basic idea.

exiftool -Echo "Reducing spaces in Description" -if "$Description=~/  +/" "-Description<${Description;s/  +/ /g}" -execute -Echo "Reducing spaces in Caption-Abstract" -if "$Caption-Abstract=~/  +/" "-Caption-Abstract<${Caption-Abstract;s/  +/ /g}" -common_args -P -overwrite_original -progress /path/to/files/

This is exactly the same as if I ran
exiftool -Echo "Reducing spaces in Description" -if "$Description=~/  +/" "-Description<${Description;s/  +/ /g}" -P -overwrite_original -progress /path/to/files/
followed by running
exiftool -Echo "Reducing spaces in Caption-Abstract" -if "$Caption-Abstract=~/  +/" "-Caption-Abstract<${Caption-Abstract;s/  +/ /g}" -P -overwrite_original -progress /path/to/files/

Everything after the -Common_Args option is duplicated across both commands.  Take note that you do not have a trailing -execute before the common_args option.  This was something that confused me at one point.

Also remember that common_args can only be used on the command line, not as part of an -@ args file.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

ghelfrich919

Yes, it's running on a NAS share. I copied the photos to a different share and tried running it on there.  Throughout the day today, I've been running the script numerous times and I haven't had the same issue once.  So it looks like I have a disk issue. 

And thanks for the details on common_args.  I'll see how I can use it in my case.

Gerry