exiftool 12.50 hangs on empty subdirectory?

Started by Happy Hobo, December 14, 2022, 02:59:06 PM

Previous topic - Next topic

Happy Hobo

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.

StarGeek

What is your exact command?  Are you sure it's not your script that has the problem instead of exiftool?
"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

Happy Hobo

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.

greybeard

#3
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.

StarGeek

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.

"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

Phil Harvey

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

Happy Hobo

#6
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?

Happy Hobo

If an error outputs help text, shouldn't that go to stderr?

Phil Harvey

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

Happy Hobo

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.

Phil Harvey

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

Happy Hobo

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!"

Phil Harvey

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