Program name: how does it change behaviour?

Started by terrypin, March 19, 2013, 01:15:53 PM

Previous topic - Next topic

terrypin

This has been puzzling me since I installed ExifTools GUI with its associated files.

If I drag a JPG to exiftool.exe then it displays briefly and closes. If I drag it to a copy re-named exiftool(-k).exe it displays and pauses until a key is pressed. Yet they are identical executables apart from their names. How can that make the 'k' option operative? It's not as if these are shortcuts, like these, only the second of which has the pause parameter specified.
Name = Original, Target = C:\WINDOWS\exiftool.exe
Name = Display All, Target = C:\WINDOWS\exiftool.exe -k

I'm sure this will prove embarrassingly obvious, but so far the penny hasn't dropped!

--
Terry, East Grinstead, UK

Phil Harvey

Hi Terry,

The executable actually knows its name, and I have used this property to allow options to be embedded inside brackets in the name of the executable.

It's a neat trick that I've never seen done by any other executable, but it makes it easy to add simple options.  The -k option keeps the window open after the command is run.

This is definitely not obvious, but you can read about this in the application documentation (view this by running ExifTool with no arguments):

    This stand-alone Windows version allows simple command-line options to
    be added to the name of the executable (in brackets and separated by
    spaces at the end of the name), providing a mechanism to use options
    when launched via the mouse. For example, changing the executable name
    to "exiftool(-a -u -g1 -w txt).exe" gives a drag-and-drop utility which
    generates sidecar ".txt" files with detailed meta information. As
    shipped, the -k option is added to cause exiftool to pause before
    terminating (keeping the command window open). Options may also be added
    to the "Target" property of a Windows shortcut to the executable.


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

terrypin

Thanks Phil, that's been nagging at me for a day or so. First time in 30 years using PCs that I've ever seen a program that can read its own varying name - very clever!

In practice though wouldn't that mean copying the entire 5 MB executable for every variation? In fact that's what I was doing until earlier today.  :)

--
Terry, East Grinstead, UK

Phil Harvey

Hi Terry,

Yes.  So this technique is only suitable for a very few combinations of options.  For more, I recommend using the Target properties of a Windows shortcut.   I give this hint in the "Running ExifTool" section of the home page:

Hint: Options may also be added to the "Target" property of a Windows shortcut for the executable. Using a shortcut has 3 advantages over adding options in the file name: 1) different shortcuts may be created without requiring multiple copies of the executable, 2) characters which are invalid in file names may be used, and 3) the shortcuts can be given more meaningful (and convenient) file names.

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