Exiftool from VB.

Steve36445

Well-known member
Joined
Dec 23, 2007
Messages
58
Programming Experience
10+
6/17/2016 3:12:21 PM



Can you help me please?

I am trying to write an Exif tag editor (for .jpg images).

Exiftools seems to show promise, but I need to access it through Visual Basic (to set tags).
ExifTool by Phil Harvey

I do not understand why the line

"exiftool -csv d:\test\_DSC0214.JPG >d:\test\exifoutput.csv"

Works from the command prompt but.

VB.NET:
'  Dim shellstring As String = "exiftool -csv  d:\test\_DSC0214.JPG >d:\test\exifoutput.csv" '

Shell(shellstring)



Does not work within Visual Basic, it does not give them error but it does not create file either.

Furthermore-

Process.Start(shellstring)
produces an error-
"win32exception was unhandled"
"the system cannot find the specified file"

Apparently this is something to do with me running a 64bit system

Windows Version Microsoft Windows 10 Pro Build 10586 64-bit

Allthough none of the online fixes seem to work.

Visual Basic 2010 express.
Thanks,

Steve
 
Firstly, don't use Shell in VB.NET. Always use Process.Start. Secondly, when you do use Process.Start, pass it the correct arguments. You clearly haven't read the documentation for the Process.Start method if you think passing it that String is going to work. I would suggest always reading the documentation for new types and members but especially if you try to use them and they don't work. VS has a Help menu for a reason.

As for the issue, my guess is that it's related to the working directory for the Process, which will be your app's current directory by default. You may have to set the working directory to the folder containing the exiftool EXE for that commandline to work. I would suggest creating a ProcessStartInfo object, which allows you to set the file name, commandline arguments and working directory, and then pass that to your Process.Start call. If that doesn't work then I don't know what the problem is.
 
thank you for your reply.
It would help me to know why I shouldn't use the shell statement I have had good success with it in the past. This is not a flippant comment, I do not doubt that there is good reason, I would just like to know to improve my understanding.
secondly, I do use the help facility and search the Internet extensively, I have programmed for over 20 years (as Hobby) and perhaps made a only a dozen, or so request on help forums, I thought that was the idea ask for help when you get stuck.

I tried numerous Process.start methods with no success. For brevity I did not detail all. I simplified the code to isolate the error.
It would help me tremendously if you would suggest code, as I have struggled with this for several hours and am clearly missing something.

Thanks again,

Steve
 
Don't use Shell because it is a holdover from VB6 and there for compatibility more than anything else. Process.Start provides more and better functionality.

If you have read the documentation for the Process.Start method then you know that it requires that you specify the file to execute and any commandline arguments to be passed to that executable separately. You are not doing that in the code you showed, which suggested to me that you had not read the documentation for this particular method.

As I said, you should create a ProcessStartInfo object, specify the file to execute, the commandline arguments and the working directory and then pass that object to Process.Start. I assume that you realise that the working directory must be the folder that contains the file being executed. That said, if that folder is included in the system PATH variable then that should not be required.
 
thanks John,
amongst other things I try this-

VB.NET:
Dim myprocess As New Process

        myprocess.StartInfo.Arguments = " -csv  d:\test\_DSC0214.JPG >d:\test\exifoutput.csv"
        myprocess.StartInfo.FileName = "exiftool"
        myprocess.Start()
But it didn't work the command window opened up with the exiftool indicating to me that the bit that confused it was indeed the arguments. but it works fine from the command line indicating to me that there is probably an error in vb producing the string that gets to the 'command line' or whatever.

I would have thought that both shell and the process method produce a string that is sent to another piece of code that implements the command line, I can only think that there is a problem generating this code.

Do you know if there are any issues involved with 64Bit addressing.

I also set the working directory to the photograph Directory and this didn't help.

I realise I may not understand the correct terminology, I am not a programmer by trade, just a Humble physics teacher, so please bear with me.

Thanks,

Steve
 
Try wrapping each of the file paths in double quotes. It doesn't look like it should be necessary but obviously something doesn't work the way it appears that it should so educated guesses are all I have at this point..
 
">" is a redirection operator for cmd shell, it will not work as an argument for that process. For Process class have a look at ProcessStartInfo/RedirectStandardOutput Property. Possibly you can use the -o output file option instead, I'm not exactly sure how that tool works.
 
exif tool vb

thanks for the tips John I seem to have it working now, using your help (and the websites shown) I redirected the output to a stream reader and have read into a textbox which I can process further,

VB.NET:
Sub Process_file(File_name As String)
      
        ' ''https://msdn.microsoft.com/en-us/library/system.drawing.imaging.propertyitem(v=vs.110).aspx
        'https://msdn.microsoft.com/en-us/library/system.diagnostics.process.startinfo(v=vs.110).aspx

        Dim myprocess As New Process
        myprocess.StartInfo.UseShellExecute = False

        myprocess.StartInfo.Arguments = " -csv  d:\test\_DSC0214.JPG"
        myprocess.StartInfo.FileName = "exiftool"
        myprocess.StartInfo.RedirectStandardOutput = True

        myprocess.Start()
        Dim reader As StreamReader = myprocess.StandardOutput
        Dim result As String = reader.ReadToEnd()
        TextBox1.Text = (result)
     
    End Sub
 

Latest posts

Back
Top