Using stay_open and visual basic

Started by Skippy, September 17, 2015, 11:47:21 PM

Previous topic - Next topic

Skippy

Have got the code to run but I can't seem to get the results via StdOut.

The following code was drafted in ms-access 2010 and it runs to completion but I suspect that exiftool is not being called correctly.

Option Compare Database
Option Explicit

Private Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)

Public Function ArgFile()

    'object variables
    Dim fso As Object
    Dim wso As Object
    Dim w As Object
    Dim fileobj As Object
    Dim ScriptObj As Object
    Dim ts As Object
   
    'scalar variables
    Dim CmdString As String
    Dim ExifToolOutput As String
    Dim FileSpec As String
   
    'Create empty arg file
    Set fso = CreateObject("scripting.filesystemobject")
    FileSpec = "F:\Skippy\Development\PhotoHarvester\Access\Dev\exifArg.arg"
    Set w = fso.createtextfile(FileSpec, True, False)
    Set fileobj = fso.getfile(FileSpec)
    w.Close
   
    Set wso = CreateObject("WScript.Shell")
    CmdString = "F:\Skippy\Development\PhotoHarvester\Access\Dev\exiftool.exe -stayopen @ "F:\Skippy\Development\PhotoHarvester\Access\DevexifArg.arg"
    Set ScriptObj = wso.exec(CmdString)
    Debug.Print ScriptObj.stdout.readall
    '//The stdout above works: output below
        '//1 directories scanned
'//0 image files read
'//3 files could not be read

    Debug.Print "Started"

    'Code for appending more lines to the existing arg file. Normally this would be a loop and args for lots of files would be added
    Set ts = fileobj.OpenAsTextStream(8, -1)
    ts.writeline "-iso"
    ts.writeline "-ImageUniqueID"
    ts.writeline "-SerialNumber"
    ts.writeline "-Model"
    ts.writeline "C:\Temp\exif\141_0604\DSCN6400.JPG"
    ts.writeline "-Execute1"
    ts.writeline vbCr
    ts.Close
   
    'Sleep for a second to allow processing.  Then try to get stdout
    Sleep (1000)
    Debug.Print "Slept"
    Debug.Print ScriptObj.stdout.readall
   
    'Close exiftool
    Set ts = fileobj.OpenAsTextStream(8, -1)
    ts.writeline "-stay_open"
    ts.writeline "False"
    ts.writeline vbCr
    ts.Close
   
End Function


The line feeds are working because the exiftool window appears then closes.

The feedback in the immediate window is:

======== F:/Skippy/Development/PhotoHarvester/Access/Dev/exifArg.arg
    1 directories scanned
    1 image files read
    2 files could not be read

Started
Slept

Exited


So exiftool scanned the dev folder which has no photos.  The exifArgs.arg contents are as below:

-iso
-ImageUniqueID
-SerialNumber
-Model
C:\Temp\exif\141_0604\DSCN6400.JPG
-Execute1


-stay_open
False


I am not sure why there is no feedback when the arg file is processed.  I don't know how to proceed. All help appreciated.

The big question is stay_open even able to be used for reading tags rather than writing them?

Phil Harvey

Yes, absolutely, -stay_open may be used when reading tags.  The ExifToolGUI uses -stay_open exclusively for all operations for example.

I don't understand this line at all:

    CmdString = "F:\Skippy\Development\PhotoHarvester\Access\Dev\exiftool.exe -stayopen @ "F:\Skippy\Development\PhotoHarvester\Access\DevexifArg.arg"

The quotes don't seem to match up, and there are many things wrong with your command if it contains -stayopen @.  If so, try reading the exiftool documentation a bit more closely next time.

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

Skippy

Sorry, the command string got mangled somehow.
The documentation is not always clear to me. 
cat a.jpg | exiftool -
Extract information from stdin.


For example I do not know what the pipe character does in the above example.  I usually use the pipe as a delimiter but I am not sure what it does in the piping example.  Is the trailing 'exiftool' a processing instruction?  A few more examples would help as I need to see the pattern. 

Getting the second instruction to Exiftool in a VBA environment or any microsoft scripting language seems to be rather difficult and I am facing a lot of error messages.  It would be great to have a clearer understanding of what exiftools expects to see coming through stdIn on the commands issued after the command that opens exiftool. 

You help so far is truly appreciated.

Phil Harvey

You should read about piping in your shell (cmd.exe).  This is not an ExifTool feature.

And ExifTool doesn't expect any input from stdin -- it only reads from the file you specify.  If you specify "-" as a file, then it reads from stdin, but as far as exiftool knows it is just the same as any other file.  To get it to read arguments from stdin, you specify -@ -.  The documentation for the -@ option explains how this input should be formatted.

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