exiftool command line doesn't work when calld from python

Started by Jean-Michel, November 13, 2024, 02:11:03 PM

Previous topic - Next topic

Jean-Michel

Hello

I'm trying to call exiftool from a python code
The command line I want to execute is
exiftool -if '$jpgfromraw' -b -jpgfromraw -w %d%f.jpg -execute -if '$previewimage' -b -previewimage -w %d%f.jpg -execute -tagsfromfile @ -srcfile %d%f.jpg -overwrite_original -common_args --ext jpg test1.dng

The command works well from the shell:
$ exiftool -if '$jpgfromraw' -b -jpgfromraw -w %d%f.jpg -execute -if '$previewimage' -b -previewimage -w %d%f.jpg -execute -tagsfromfile @ -srcfile %d%f.jpg -overwrite_original -common_args --ext jpg test1.dng
    1 files failed condition
    0 output files created
Warning: [Minor] Not decoding some large array(s). Ignore minor errors to decode - test1.dng
    1 output files created
Warning: [Minor] Not decoding some large array(s). Ignore minor errors to decode - test1.dng
    1 image files updated

The test1.jpg is created, metadata are attached as expected

But it fails when called from a simple python code:
import os

os.system("exiftool -if '$jpgfromraw' -b -jpgfromraw -w %d%f.jpg -execute -if '$previewimage' -b -previewimage -w %d%f.jpg -execute -tagsfromfile @ -srcfile %d%f.jpg -overwrite_original -common_args --ext jpg test1.dng")

Resulting execution is:
$ python _test.py
    1 files failed condition
    0 output files created
    1 files failed condition
    0 output files created
Warning: [Minor] Not decoding some large array(s). Ignore minor errors to decode - test1.dng
Error: File not found - test1.jpg
    0 image files updated
    1 files weren't updated due to errors

It looks like at some point exiftool is not able to write the JPG

I have tried using `os.system()` as well as `subprocess.run()` without any success

Is there a way to get more debug or any hints ?

StarGeek

Simplify the exiftool command down to just one step and see if that works.

Is python replacing anything in the code (I don't know enough about Python variables)? For example, is it replacing the tag names with the leading dollar sign with Python variables?
"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

I think StarGeek is likely correct (good catch!).  This would cause the exact output you are seeing.

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