Arguements not parsed as python list in subprocess

Started by StoneMonkeyMark, August 28, 2019, 11:43:06 AM

Previous topic - Next topic

StoneMonkeyMark

I was using subprocess in a python program and found that some arguements do not work if sent to the windows exe as a list.
It does work as a single string.
Looks like it has to do with the way the shell is invoked.
Some arguements generate the "Invalid TAG name:" error when it should be parsing them as a normal arguement to the exiftool.exe.
I have the work around but thought your might like to see this.


import subprocess

exiftool_arguements_list = ['exiftool.exe', '-e', '-a', '-s', '-ee', '-G0:1:2', '-ApertureValue', '-r.', '-ext *', 'D:\\Test']
print("subprocess.run as one string")
subprocess.run(" ".join(exiftool_arguements_list))
print("subprocess.run as list of arguements")
subprocess.run(exiftool_arguements_list)



The output on a test DIR with a text file and two jpgs where only one jpg has an ApertureValue value is:

subprocess.run as one string
======== D:/Test/1999/b.JPG
======== D:/Test/a.jpg
[EXIF:ExifIFD:Image] ApertureValue              : 1.8
======== D:/Test/c.txt
Error: File is empty - D:/Test/c.txt
    2 directories scanned
    3 image files read
subprocess.run as list of arguements
Invalid TAG name: "ext *"
======== D:/Test/1999/b.JPG
======== D:/Test/a.jpg
[EXIF:ExifIFD:Image] ApertureValue              : 1.8
    2 directories scanned
    2 image files read

Phil Harvey

Some options have additional arguments which must be separate, like this:

exiftool_arguements_list = ['exiftool.exe', '-e', '-a', '-s', '-ee', '-G0:1:2', '-ApertureValue', '-r.', '-ext', '*', 'D:\\Test']
...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 ($).

StoneMonkeyMark

Thanks, and understood.
So any args separated by a space are like this?
eg. -if would be the same. But they are order dependant.
Is this mentioned anywhere? I did try to search the docs and forums.

Phil Harvey

This isn't mentioned anywhere because it isn't related to ExifTool.  It is simply how how the shell parses command-line arguments.  Exiftool parses the arguments for the -@ argfile option, and the -@ documentation mentions that separate arguments must be on separate lines.  This is similar to the problem you have, but you aren't using the -@ feature.

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

StoneMonkeyMark

Thanks, sadly I did see the -@ file posting and did not connect the two.
And a special thanks for the speed of the replies.