Strange problem when using successful code in another project

Started by Deret, December 15, 2014, 11:18:25 AM

Previous topic - Next topic

Deret

I spent some time last week experimenting with Exiftool using Visual Studio Community.  I created code for writing/reading metadata and with a bit of tweaking and some research I managed to get everything working perfectly and I was greatly impressed.  Today, I used the same code in another VS project being careful to copy and paste the code in plain text so that no hidden control characters were included and found that under exactly the same conditions, the code for writing metadata no longer works (I haven't tried any of the other operations).  VS doesn't throw any errors and all seems to be well, except that the metadata is not written to the image file.  I thought at first that the problem might be an incorrect file name passed to Exiftool, but I've checked and double-checked.  Any suggestions greatly appreciated.

Phil Harvey

I suggest that you debug this by printing the exiftool command lines, then trying them yourself at the console to see if there are any problems.  Usually things like this are easily caught if you can see the warning/error messages.

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

Deret

Thanks for that lightning fast reply, Phil.  The command sent to Exiftool is a concatenated string of commands for writing to the appropriate tags.  I've dumped the string to a text file and examined it, but can't see anything amiss.  I'm not sure what you mean by printing the commands, unless you mean what I've just described.

Phil Harvey

That's what I meant.  Can you paste this into a console window to try running the command?

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

Deret

This gets stranger!

I tried running the code in a console window with the same result - no errors, but no metadata written to the file.  I have the Exiftool code in a sub, so all I need to do is call the sub, passing just the path and name of the file.  This works every time without fail in the first project (the one that I used to test and develop the code).  In the second project, where conditions are just the same, I have placed the sub calling code in various places and sometimes it works and sometimes it doesn't even though no code is changed, in fact nothing is changed.  If I ever crack this one, I'll let you know!

Phil Harvey

This should be easy to crack since you can duplicate the problem at the command line.

Try adding a -v3 to the command to get lots of details about what ExifTool is doing.  If you can narrow it down to a single file, send me the file and the command and I'll tell you what the problem is.

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

Deret

Well now... Why is it that something can be right in front of your face, but you can't see it?

On the form that I intended to use for writing the metadata I have a picture box displaying the image.  The file stream that I open to display the image is left open, therefore as far as the system is concerned, the image is open in another application and therefore cannot be written.  One line of code to close the file stream was all I needed and now everything works perfectly every time.

I have banged my head against the desk several times in the hope that I'll never again overlook the obvious!  Thanks for all your help Phil - Exiftool is simply superb.

Phil Harvey

Excellent.  I'm glad you figured this out.  For things like this I can't help much, except by acting as a sounding board.

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