ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Happy Hobo on December 14, 2022, 02:59:06 PM

Title: exiftool 12.50 hangs on empty subdirectory?
Post by: Happy Hobo on December 14, 2022, 02:59:06 PM
I've been running a script to update some metadata, then create CSV and GPX files on everything in a directory.

If there is a subdirectory, even if it is empty, the script never finishes (I never get a command prompt until I kill the script) although the expected output files are there.

I don't know whether this is due to something in exiftool, or something in the way APFS (filesystem) works.
Title: Re: exiftool 12.50 hangs on empty subdirectory?
Post by: StarGeek on December 14, 2022, 03:11:37 PM
What is your exact command?  Are you sure it's not your script that has the problem instead of exiftool?
Title: Re: exiftool 12.50 hangs on empty subdirectory?
Post by: Happy Hobo on December 17, 2022, 12:53:36 AM
The command is
  exiftool -c "%+.6f"           \
           -p ~/bin/gpxu.fmt    \
           -userparam name="$3" \
           -userparam desc="$4"   $(ls | sort)  >  /tmp/${2}-u.gpx

If $pwd contains a directory, empty or not, the output file is created but the command prompt never comes back.  If $pwd contains only files, the output file is created and the command prompt returns.
Title: Re: exiftool 12.50 hangs on empty subdirectory?
Post by: greybeard on December 17, 2022, 04:09:56 AM
The problem seems to be that you aren't providing the required FILE parameter when there are no files - this isn't the same thing as giving a FILE parameter that doesn't resolve to valid files.

This should mean that exiftool displays its documentation - I couldn't replicate your hang but if you run the command without redirection it will show the first page of documentation and then "hang" until you respond.

A workaround would be add the name of an empty directory before the $(ls | sort).

I'm sure the resident gurus will have a more elegant solution.
Title: Re: exiftool 12.50 hangs on empty subdirectory?
Post by: StarGeek on December 18, 2022, 11:19:56 AM
Quote from: greybeard on December 17, 2022, 04:09:56 AMThis should mean that exiftool displays its documentation

I would guess that his is almost certainly what is happening.  Under Windows CMD and PowerShell, it looks like exiftool recognizes that redirection and doesn't pause the output, but under the funky broken shell I prefer, it hangs exactly like this.

Title: Re: exiftool 12.50 hangs on empty subdirectory?
Post by: Phil Harvey on December 19, 2022, 09:31:18 AM
exiftool runs perldoc to print the help documentation if there are no input files and no tags specified on the command line.  This may be causing the hang.  Adding -dummy to the command (for a non-existent tag name) will stop it from trying to print the help documentation, and shouldn't affect the output otherwise.

- Phil
Title: Re: exiftool 12.50 hangs on empty subdirectory?
Post by: Happy Hobo on December 23, 2022, 10:14:14 PM
There ARE input files but the last thing from ls | sort is a subdirectory.  If I name only the subdirectory, it does all the files within it (if there are any).  But when the subdirectory is the last item in the sort, it hangs, even if there are files in the subdirectory or if there are not.  So I have to move all the files out of the subdirectories and delete the empty subdirectories. 

But I just remembered a detail I was forgetting: usually the subdirectory name contains spaces.  So the sort outputs a list of numeric file names, and then all the words in the subdirectory name, each of which (by itself) doesn't exist as a file or directory.  So that must be the error that makes it hang.

But why is the help text not seen in the output file?  Buffering?
Title: Re: exiftool 12.50 hangs on empty subdirectory?
Post by: Happy Hobo on December 23, 2022, 10:55:31 PM
If an error outputs help text, shouldn't that go to stderr?
Title: Re: exiftool 12.50 hangs on empty subdirectory?
Post by: Phil Harvey on December 24, 2022, 08:10:35 AM
It seems you are using zsh on Mac because the $(ls|sort) syntax doesn't work for other shells I tried.

I can't reproduce the issue.  If I run this command

exiftool $(ls|sort)

in this directory

% ls -l
total 32
-rw-r--r--  1 phil  staff  14598 21 Dec 08:46 PDF.pdf
drwxr-xr-x  2 phil  staff     64 24 Dec 08:01 ZZZ

then I get output from PDF.pdf and nothing from ZZZ since it is an empty directory.  The command does not hang.

If I add a space in the directory name (renamed it to "ZZZ 222") I get this:

% exiftool $(ls|sort) -filename
======== PDF.pdf
File Name                       : PDF.pdf
Error: File not found - ZZZ
Error: File not found - 222
    1 image files read
    2 files could not be read

And still no hang.

Since your command splits file names into separate words, I can get it to hang if I put a file such as "this - that.jpg" in the directory because "-" represents input from the console.  I would recommend doing this instead:

ls | sort | exiftool -@ - ...

Which should work with any file name.

- Phil
Title: Re: exiftool 12.50 hangs on empty subdirectory?
Post by: Happy Hobo on December 26, 2022, 03:03:06 AM
Others suggested that a prompt I needed to respond to is what it was waiting for but that I didn't see it due to my redirect.  All I know is that it did hang and I saw no error message in the shell or in the output file.  Removing the subdirectory after moving its contents to the parent prevents the hang.
Title: Re: exiftool 12.50 hangs on empty subdirectory?
Post by: Phil Harvey on December 26, 2022, 08:05:25 AM
I think we need to conclude that this is operator error.  I have demonstrated a way that this could happen but you haven't given me enough information to be able to reproduce what your situation.

- Phil
Title: Re: exiftool 12.50 hangs on empty subdirectory?
Post by: Happy Hobo on August 14, 2023, 02:20:33 PM
Not sure what other information I can put in.  Multiple image files in path-1/path-2.  I move them all into path-1, leaving path-2 empty.  Running a script that contains
cd path-1
exiftool (options) *
processes all the files alphabetically before path-2 and then hangs.  When killed, the files alphabetically after path-2 have not been done.

The simple workaround is "Don't forget to remove the empty directory!"
Title: Re: exiftool 12.50 hangs on empty subdirectory?
Post by: Phil Harvey on August 19, 2023, 07:51:21 AM
Am I correct that you are running zsh?

What happens if you recreate this file structure and sequence of commands?:

% ls -R
a.jpg b c.jpg

./b:
% exiftool -filename *
======== a.jpg
File Name                       : a.jpg
======== c.jpg
File Name                       : c.jpg
    1 directories scanned
    2 image files read
%

The above is zsh on MacOS 10.14.6 and an APFS filesystem.

- Phil