exiftool .Net wrapper (written in vb.net)

Started by Curtis, June 09, 2014, 05:31:48 PM

Previous topic - Next topic

FixEUser

@saul: Just to be sure
Have you ever tried the ".Net wrapper for the excellent ExifTool" from Mike Morano?
Available as Nuget package. This one even offers a .GetTagsAsync which accepts a FilePath or IO.Stream.

@Curtis: No offense meant  :-X

andrewj

Hi Curtis
I'm trying to run a command which requires embedding a filename within the command itself:
QuotesCmd = "-tagsfromfile """ & sJPEGFilename & """ -exif -makernotericoh -make -model -IFD0 "

For example, that becomes the following, which works fine from the command line:
Quote-tagsfromfile "E:\Pictures\Incoming\Ricoh Theta\161121_RTH_0010233.jpg" -exif -makernotericoh -make -model -IFD0

I'm having great difficulty getting it to process correctly. I have tried wrapping the filename in double quotes, single quotes, double quotes prefixed by a backslash. All to no avail. Either the command returns with a blank result, or it just hangs.

What's the best way to include a filename to avoid this?
Thanks
Andrew

Phil Harvey

Hi Andrew,

Does it work without quotes for files with no spaces in the file name?:

sCmd = "-tagsfromfile " & sJPEGFilename & " -exif -makernotericoh -make -model -IFD0"

- Phil

P.S. What is the -IFD0 for?  I don't think this will do anything.
...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 ($).

andrewj

Hi Phil
With no quotes the command throws an exception:

Exception thrown: 'System.ArgumentOutOfRangeException' in System.Windows.Forms.dll
-tagsfromfile E:\Pictures\Incoming\Ricoh Theta\161122_RTH_0010236.jpg -exif -makernotericoh -make -model -IFD0

As I said, this works fine from the command line.
Andrew

andrewj

Hi,
I've cracked it. If you use the "tagsfromfile" or similar commands, then stdErr is awaiting input before the command can complete. If you run using "shell" or from the command line this is obvious, as there is a very obvious "Press Enter to continue prompt".

To get this to work you need to redirect stdInput and send it a blank line as input. Then when the command gets to the point where it needs the input, there's a buffered line waiting for it.

Here's my code which runs this. I suspect that the internal implementation of ExifToolIO is very similar, and if Saul can just add the two lines with the 'XXX comments then the problem will go away.
   Public Function RunProcess(sExecutable As String, sParameters As String, Optional sDirectory As String = "") As ProcessOutput
        ' Execute pricess in hidden window and capture output
        Try
            Dim oOutput As New ProcessOutput
            Dim pProcess As New System.Diagnostics.Process()            ' Create process
            pProcess.StartInfo.FileName = sExecutable                   ' Set executable and parameters
            pProcess.StartInfo.Arguments = sParameters
            pProcess.StartInfo.UseShellExecute = False                  ' Control execution visibility
            pProcess.StartInfo.CreateNoWindow = True
            pProcess.StartInfo.RedirectStandardOutput = True            ' Set outputs of program to be written to process output stream
            pProcess.StartInfo.RedirectStandardError = True
            pProcess.StartInfo.RedirectStandardInput = True               ' XXX Add This XXX
            If sDirectory <> "" Then pProcess.StartInfo.WorkingDirectory = sDirectory
            pProcess.Start()                                            ' Start the process
            pProcess.StandardInput.WriteLine("")                        ' XXX Complete processing, equivalent of pressing return to continue XXX
            pProcess.WaitForExit()                                      ' Wait for process to finish
            oOutput.StdOutput = pProcess.StandardOutput.ReadToEnd()     ' Read outputs
            oOutput.StdError = pProcess.StandardError.ReadToEnd
            Return oOutput
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Function


Andrew

StarGeek

Quote from: andrewj on March 09, 2020, 01:23:23 PMIf you run using "shell" or from the command line this is obvious, as there is a very obvious "Press Enter to continue prompt".

Are you sure you haven't accidentally included the -k (pause) option?  Either directly in the command or as (-k) as part of the exiftool.exe name e.g exiftool (-k).exe?
"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

SCM

Longtime fan of ExifTool, first attempt to use it within another program.

I've created a small image watermarking program in VB2019 for others at my work. I load an image, it gets placed in a VB picturebox as a bitmap, the user can carry out minor alterations, and a watermark style is selected and added. While any supported image can be opened, it only saves in JPEG. As part of the save process, and 'in the background', I'd like to add in a standard line to the copyright field of the exif metadata. The bitmap in the picturebox is saved as a JPEG using a standard save file dialog.

I'm been playing around with the wrapper (least I think I have) and cannot seem to get it working with the image from the picturebox. I'm very novice at VB coding so I'm probably overlooking something.

I've tried converting the bitmap directly to a type that Visual Studio doesn't throw an error for but no luck, various errors halt the program at the execute commend. Some Googlefu has turned up bits and pieces, such as sending the bitmap through a memory stream, but I'm at a loss for even a starting spot.

Thanks everyone in advance!