Author Topic: exiftool .Net wrapper (written in vb.net)  (Read 32400 times)

FixEUser

  • Full Member
  • ***
  • Posts: 32
Re: exiftool .Net wrapper (written in vb.net)
« Reply #30 on: November 23, 2019, 01:12:36 PM »
@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

  • Full Member
  • ***
  • Posts: 31
Re: exiftool .Net wrapper (written in vb.net)
« Reply #31 on: February 13, 2020, 08:59:21 AM »
Hi Curtis
I'm trying to run a command which requires embedding a filename within the command itself:
Quote
sCmd = "-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

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16885
    • ExifTool Home Page
Re: exiftool .Net wrapper (written in vb.net)
« Reply #32 on: February 13, 2020, 09:21:27 AM »
Hi Andrew,

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

Code: [Select]
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, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

andrewj

  • Full Member
  • ***
  • Posts: 31
Re: exiftool .Net wrapper (written in vb.net)
« Reply #33 on: February 25, 2020, 02:53:31 PM »
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

  • Full Member
  • ***
  • Posts: 31
Re: exiftool .Net wrapper (written in vb.net)
« Reply #34 on: March 09, 2020, 01:23:23 PM »
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.
Code: [Select]
   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

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3964
Re: exiftool .Net wrapper (written in vb.net)
« Reply #35 on: March 09, 2020, 04:26:43 PM »
If 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?
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.