ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: ESN on August 09, 2011, 03:29:31 AM

Title: -csv doesn't work when called from vba - ?
Post by: ESN on August 09, 2011, 03:29:31 AM
Trying to call exiftool from an Access application and no matter how I adjust the syntax I can't get a csv file out of it.  Sorry for the slop - this is just a quick test code:

Public Function ImportTemps()

Dim strImgPath As String
Dim strOutPath As String
Dim strProgPath As String
Dim strOptions As String
Dim strShellCmd As String

Dim intTempF As Integer
intTempF = 0

strImgPath = Chr(34) & "C:\Users\Eric\Desktop\temp\031" & Chr(34)
strOutPath = Chr(34) & "C:\Users\Eric\Desktop\out.csv" & Chr(34)
strProgPath = "C:\Users\Eric\Desktop\exiftool-8.61\exiftool.exe"
strOptions = " -FileName -AmbientTemperatureFahrenheit -t -csv -k"

strShellCmd = strProgPath & strOptions & " " & strImgPath & " > " & strOutPath
   
Me.Text2 = strShellCmd

Shell (strShellCmd)

...
End Function


I've tried everything I can think of to make this work, including changing the output file path, changing the order of the options in the shell command string, etc.  What's strange is that if I copy the string exactly as it appears in Me.Text2 into a command prompt and run it directly, everything works perfectly - Exiftool creates the csv on my desktop.  The only results displayed in the command window are a quick summary: "1 directories scanned - 1239 image files read."  When I call the same command from VBA, the command window lists each file with its file name and temperature tags, then says "1 directories scanned - 1239 image files read - 1 files could not be read."  Any idea where the ghost file is coming from, or why -csv isn't working from VBA?

Thanks in advance,
Eric
Title: Re: -csv doesn't work when called from vba - ?
Post by: Phil Harvey on August 09, 2011, 06:56:54 AM
It could be that your Shell() function doesn't support redirection.  Typically, the way to do this from a program is to do the redirection yourself by capturing the stdout from exiftool and writing this to a file yourself.

- Phil
Title: Re: -csv doesn't work when called from vba - ?
Post by: ESN on August 09, 2011, 04:43:23 PM
Thanks for getting back to me so quickly Phil - any hints on how I could "capture the stdout from Exiftool?"  Sorry if it's a dumb question, I'm just getting a handle on vba.
Title: Re: -csv doesn't work when called from vba - ?
Post by: Phil Harvey on August 09, 2011, 06:18:07 PM
Did you look at the Virtual Basic sample in the Programming Resources (https://exiftool.org/index.html#related_prog) of the ExifTool home page?

- Phil
Title: Re: -csv doesn't work when called from vba - ?
Post by: ESN on August 10, 2011, 12:49:56 AM
I tried that but it didn't make too much sense to me the first time around.  I'm giving it a second shot now though and I think I'm getting it.  Thanks again!