Project

General

Profile

exiv2 and wildcards

Added by T Modes about 8 years ago

I have a question concerning wildcards for filenames (on Windows).

Exiv2.exe from the official download works fine with filename wildcards: "exiv2 -pt *.jpg" processes all jpg files in the directory.

My own compilation from the MSVC (tested 2010 from 2008 project, and 2013 from 2012 project) does not read the wildcards:
exiv2 -pt .jpg
results in:
.jpg: Failed to open the file

What is the reason for this behaviour?

Thanks


Replies (4)

RE: exiv2 and wildcards - Added by Robin Mills about 8 years ago

This is due to a difference between the bash shell in Unix (and Mac, Cygwin, MinGW and Linux) and cmd.exe on Windows (DOS).

Bash expands wild cards from the command line before calling exiv2. cmd.exe presents the argument directly to exiv2 (who has not code to expand it). You can address to some extent with the for in cmd.exe. For example:

for %f in (*.jpg) do exiv2 %f
This is not identical to the bash behavior because DOS runs a loop and invokes exiv2 multiple times. Bash on the other hand invokes exiv2 once and presents all the filenames.

I personally always install Cygwin on Windows and use bash. Your mileage may differ! The Dostips web site: http://www.dostips.com shows many ingenious ways to get more from DOS.

Robin

RE: exiv2 and wildcards - Added by Robin Mills about 8 years ago

Oh, and one more thing. The exiv2.exe on the web site is cross-compiled for MinGW, I think. MinGW implements bash type behavior in the executable. When you build with MSVC, command-line path expansion is not carried out by exiv2.exe.

Although I am an enthusiastic user of the Mac (and therefore Unix), I think the bash "glob" feature sucks. It is a horrible bug that can never be irradiated - almost as bad as the \ path separator in DOS, the tab in makefile, or CRLF in Dos ascii files. To compound the awfulness of "glob", MinGW and Cygwin implement it in different ways. As you've discovered MinGW does it in the executable, and Cygwin in bash. Grrrr.

Robin

RE: exiv2 and wildcards - Added by T Modes about 8 years ago

Hi Robin,

thanks for the detailed explanation.

I was/am aware of the shell globbing issues on *nix and Windows.
I thought is a missing preprocessor switch or the release have some special code.

So after your answer and the hint to Mingw I tried to build exiv2 with tdm-mingw. The result: no globbing :-( (even with mingw-gcc compiler)

So I searched further with this information.
I found the problem is the used run-time library and not directly the compiler.
So each compiler/run-time library has different approaches to deal with this issue:
  • Mingw (cross compile): shell globbing by default on, can be tuned with "int _CRT_glob=.." (not tested by me)
  • Mingw-w64: shell globbing by default off, can be activated by adding "int _dowildcard = -1;" to the source (tested, globbing works for me)
  • MSVC: shell globbing by default off, can be activated by adding "setargv.obj" to the linker dependencies. (tested, globbing works for me)

Maybe the MSVC solution could be added to the project files. I'm not sure about the Mingw approaches.

Or alternatively: write an own filename globbing algorithm to be independent from the slight differences between the different implementation (takes some time and testing)

RE: exiv2 and wildcards - Added by Robin Mills about 8 years ago

Thanks for digging deeper into this. Lots of good information here.

I would not support adding our own home made globbing. We use platform code (presumably in the C runtime library) or not at all.

Curious 'can of worms'. Thanks for bringing this to light.

Robin

    (1-4/4)