Author Topic: StdErr corrupting ExifData in Michael Wandels VB6 API code  (Read 4409 times)

Spilly

  • Newbie
  • *
  • Posts: 7
StdErr corrupting ExifData in Michael Wandels VB6 API code
« on: November 11, 2016, 10:35:25 AM »
I'm a newbie - a VERY newbie. Am very impressed by ExifTool.
BUT I've got an issue - AND a very crude workaround, which I'd like to improve.

My problem is that the exifdata I want is being corrupted sometimes with informative text like
   "70 directories scanned" and "5500 images processed" 
My code is based on Michael Wandel's exifTool wrapper for Visual Basic 6.0 [VBA in Office is very like VB6]

My question
Is there anyone here with enough Windows API knowledge to tell me how to redirect STDERR to a file OR to buffer it and insert it at the beginning or end of the data stream.  I'd rather not simply suppress all error output regardless.
I suspect that my -csv option may be contributory to the problem, but having CSV data sure does simplify the code handling the data


A bit about the wrapper
Michael's code as written pipes the results of "exiftool.exe -s FILE" into the wrapper, where it is presented as an array
Both STDOUT and STDERR are sent to the pipe.
As far as I can tell, there is normally no STDERR output for a successful -s execution, so there is no problem with the code as written.
However if you execute  "exiftool -s FOLDER  there IS output on STDERR, typically  " 3 folders scanned"  and " 20 files processed"
On small volumes this STDERR text comes at the start of the output stream as 2 rows

The trouble is that I fiddled with the code - for good performance reasons

I want to analyse ~100 folders containing ~6000 images and the Excel report includes some metadata timestamps etc.
So I changed Michael's fixed command from
     exiftool -s FILE
to 
    exifTool Options, Tags, FileOrFolder   which, for example, might expand to:
    exifTool -r. -csv -FileModifyDate -FileCreateDate -DateTimeOriginal TOPFOLDERNAME

and added code to build a keyed array for each file (row) when it arrives in the wrapper from the exiftool process.
At this point I've finished with exiftool, and with a single execution.

The rest of my Excel code re-processes the same tree extracting the metadata of each image file from the keyed array
and reports fine - given a full set of properly formed rows.


What goes wrong  (but only with larger volumes)
The File & Folders message text appears in the middle of the exiftool output

I'm sure Hayo Baan had the answer where he says in this thread https://exiftool.org/forum/index.php/topic,5056.msg29215.html#msg29215
Quote
Error messgages should go to STDERR and stay separated from the normal output to STDOUT. It looks like your code is mixing the two, and worse seems to have one in buffered mode and another in unbuffered mode, causing the error message to appear somewhere in between the normal output. My guess is, the problem lies somewhere here. It is very very unlikely that it has anything to do with exiftool itself.

That's exactly what is happening.

In Michael's original code I see this
        start.hStdOutput = hWritePipe
        start.hStdError = hWritePipe    'I have changed hWritePipe to NULL, which suppresses the stream

That at least gets me going with the rest of the project


I hope someone can help me build a more elegant solution.

Spilly






Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16885
    • ExifTool Home Page
Re: StdErr corrupting ExifData in Michael Wandels VB6 API code
« Reply #1 on: November 11, 2016, 10:59:20 AM »
Just a quick suggestion:  Have you tried contacting Michael Wandel?  His email address is in the readme.txt file.

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

Spilly

  • Newbie
  • *
  • Posts: 7
Re: StdErr corrupting ExifData in Michael Wandels VB6 API code
« Reply #2 on: November 11, 2016, 11:09:24 AM »
Will do.  Thanks.

Curtis

  • Sr. Member
  • ****
  • Posts: 115
Re: StdErr corrupting ExifData in Michael Wandels VB6 API code
« Reply #3 on: November 12, 2016, 04:26:11 PM »
Hi Spilly,

I took a quick look at Michael's code and agree with your conclusion based on what Hayo said.  If you don't need the error messages then sending STDErr to Null seems like a reasonable solution, especially if what you are doing is a 'one time' thing and not meant to be a general purpose program.

If you needed it to be faster, using the -stayopen switch for exiftool would help a lot, as the code is now it opens and closes the exiftool process for each file it processes, but with -stayopen it would be opened once, process all files and then close the exiftool process.  But, to use -stayopen you would need to modify Michael's code quite a bit.

Not much new here, just confirming what you already know.
Curtis

Spilly

  • Newbie
  • *
  • Posts: 7
Re: StdErr corrupting ExifData in Michael Wandels VB6 API code
« Reply #4 on: November 12, 2016, 05:13:07 PM »
Thanks Curtis

I too read the original code, which indeed needs -stayopen.

I decided to tweak it to process whole folder trees, extracting selected tags into CSV format.
I used the original pipe inter-process communication, so Op system files are still not involved.

I guess a perl implementation might be quicker, but I'd then have to communicate with Excel by operating system files
manage the clean up etc, as well as install a new application and maybe even learn a whole new language.

As it is, it's now quite a neat process.
This board has also kindly shown me how to fix a Windows code page issue, so the job is finished now   :)


Thanks for all the help to a newbie

Spilly