ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Wolf on June 29, 2021, 04:29:53 PM

Title: ExifTool Excel VBA
Post by: Wolf on June 29, 2021, 04:29:53 PM
I want to plot the meta data from the jpg-files in a directory.
Using the CLI with the command: 
C:\ExifTool\exiftoolgui\exiftool.exe -charset filename=Latin  -comment  -xpcomment  -DateTimeOriginal -k  L:\USB-Karte\Jagst_Kocher\*.jpg > D:\download\ExifTool\USB-Karte\Jagst_Kocher.txt
it works fine,  see attachment:  Jagst_Kocher.txt

I try to use in Excel VBA the same command, but this doesn't work.
shell_daten="C:\ExifTool\exiftoolgui\exiftool.exe -charset filename=Latin  -comment  -xpcomment  -DateTimeOriginal -k  L:\USB-Karte\Jagst_Kocher\*.jpg > D:\download\ExifTool\USB-Karte\Jagst_Kocher.txt"
taskId = Shell(shell_daten, 0)
Result: the output file is not created.

I replaced the redirection ">" with "-W+!". This produce the output file. But the content is incomplete. Missing the path with the filename.
See attachment: Jagst_Kocher1.txt, in addition the first line is on this position wrong and is the same as the last line (which is here correct).

Environment: Windows 10 Pro, Excel 2000
Can anybody help me?
Wolf
Title: Re: ExifTool Excel VBA
Post by: StarGeek on June 29, 2021, 09:01:32 PM
Quote from: Wolf on June 29, 2021, 04:29:53 PM
Result: the output file is not created.

That is because you are redirecting the exiftool output into a file and redirection is a property of CMD/Powershell, which can't be used from when calling a command from VBA.  The same thing happens with just about every programming language.

QuoteI replaced the redirection ">" with "-W+!". This produce the output file. But the content is incomplete. Missing the path with the filename.
See attachment: Jagst_Kocher1.txt, in addition the first line is on this position wrong and is the same as the last line (which is here correct).

You can either capture the exiftool output when you run it from VBA or you can add the file path to the output and parse it differently.  I can't help in the first case but there should be examples on sites such as StackOverflow.  In the second case, you could use -Directory -Filename and parse that or use -Filepath to get the absolute file path.
Title: Re: ExifTool Excel VBA
Post by: Wolf on June 30, 2021, 12:04:49 PM
Thank you StarGeek for your reply.

I found a working solution. I use an additional cmd /c command in the shell term. That works with the redirection with ">".
shell_daten = "cmd /c C:\ExifTool\exiftoolgui\exiftool.exe -charset filename=Latin  -comment  -xpcomment  -DateTimeOriginal -k  L:\USB-Karte\Jagst_Kocher\*.jpg > D:\download\ExifTool\USB-Karte\Jagst_Kocher.txt"
The open problem is, the cmd-window is still open and must be closed manually with the ENTER-command, so that the output file is filled with the ExifTool results.

With the command  Call Shell("TASKKILL /F /t /PID " & CStr(taskId), 0) the task ends, but the cmd-window is still open.
Sendkeys doesn't work in Window 10.

Perhaps anybody has a solution to close the open cmd-window from Excel VBA.
Regards
Wolf
Title: Re: ExifTool Excel VBA
Post by: Phil Harvey on June 30, 2021, 12:28:23 PM
You should be able to read stdout from the exiftool command directly (without running in cmd shell), then write it to a file yourself.

- Phil
Title: Re: ExifTool Excel VBA
Post by: StarGeek on June 30, 2021, 01:30:05 PM
You might try this SuperUser (https://superuser.com/a/699910/314998) answer and have the command run in the background without opening a window at all.

This is something I used to run a bat file in the background will I was doing other stuff.  The bat file would be processing files and open and close a window constantly, taking the desktop focus away from the program I was currently working with.  The script in that answer allowed to bat file to run in the background without opening a CMD window and grabbing focus.
Title: Re: ExifTool Excel VBA - Problem solved
Post by: Wolf on July 02, 2021, 01:55:10 PM
Thank you Phil and StarGeek for your replies.
The reason, why I use the shell command in my Excel VBA is, that I have written a VBA macro to process the ExifTool output in several columns without a separate process with the CLI and to copy the result from the CLI t to Excel.
For example:
Bildname               Comment                                        XPcomment              DateTimeOriginal
J20040604_123103.JPG   Zwischen Baiertal und Heilbronn.118_1884.JPG   Radtour Jagst-Kocher   2004:06:04 12:31:03

I solved the problem, mentioned in my last reply. The reason for the behavior is the option -k, which hold the cmd-window open.
Without the option -k, it works fine.

Best regards
Wolf