Exiftool command line in windows - Help please anyone

Started by mball, June 18, 2012, 11:10:27 AM

Previous topic - Next topic

mball

I am calling a command line program with arguments from within my application (ExifTool) I have it working fine with paths without spaces and I have it working fine when the image file I want ExifTool to use has spaces but I am having problems when the assembly directory contains spaces.

I have tried putting quotes around the whole string and I have tried putting quotes around the assemblydirectory and exiftool.exe but none of these work

This line works if the assemblydirectory doesnt have spaces in it but the filename does
string toolPath = GlobalMethods.AssemblyDirectory + @"\exiftool.exe -fast -G -t -m -q " + "\"" + filename + "\"";

There is probably a simple answer to this but I have been trying things for long enought, I hope someone can help

BogdanH

I'm affraid I can't help in this specific case.. I'm just curious: what programming language is this?
Anyway, from my experience (calling ExifTool within application), the best way is to tryout command in console window first; and if result is as expected, then use exactly the same command (as string) in your application.
As for spaces in directory (or file!) names: if there's a space in directory name, file name or if tag value contains spaces, then it must be quoted with double quotes. For example:
exiftool -G -t "c:\My Photos\*.jpg"

If not doublequoted, then ExifTool will treat above command as:
exiftool -G -t c:\My Photos\*.jpg
-here, ExifTool will recognize c:\My and Photos\*.jpg as two parameters.

I'm sorry if I didn't answer your question.
Bogdan

Phil Harvey

This quoting technique also works on the command line for the directory of the exiftool command itself, which I think is the problem.  However, it seems as if you have tried this already in your program without success.

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

mball

Yes I have tried quoting as per c#, it works if I have no spaces in the path to exiftool and put quotes around the file to work on but if the exiftool is in a folder with spaces I cant seem to get the quoting right, as putting quotes around the exiftool folder and exe doesnt work because it treats the parameters as a file and if I put quotes around the whole thing it doesnt work either

BogdanH

Probably I didn't understand correctly.. That is, the problem arises in case exiftool.exe is inside directory which name contain spaces? Meaning, if directory name (where exiftool.exe resides) contain spaces, then you have a problem to call exiftool?
I'm just trying to understand.

Bogdan

mball

Yes, I need to be able to have a space in both the exe path and the image path. I have tried this from the command line and it works fine

"c:\program files\mball business solutions ltd\photolog\exiftool.exe" -fast -G -t -m -q "D\Pictures\RAW\Test Folder\DSC00234.JPG"

in the app, I am outputting the string to the event log and it looks like this which looks pretty much the same

"C:\Program Files (x86)\MBALL Business Solutions Ltd\PhotoLog\exiftool.exe" -fast -G -t -m -q "D:\Pictures\RAW\Test Folder\DSC00274.JPG"

but when the command is run I get this as an output

'C:\Program' is not recognized as an internal or external command

Phil Harvey

It sounds like your quotes are getting eaten by the script or language parser.  Maybe you need to apply a 2nd level of quoting.  But I can only guess because I haven't seen the code that makes the actual call to execute exiftool.

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

BogdanH

I don't know C#, but I'm quite sure, that (one way or another) your code actually calls Windows CreateProcess function (see http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx ).
By assuming that's the case...
You can see, that for CreateProcess, there are two ways to define your calling (exiftool.exe) application:
1st way: you define exiftool in lpApplicationName,
2nd way: you set lpApplicationName to nil and define it in lpCommandLine.

I am using 2nd approach inside ExifToolGUI -I can do that, because I (GUI actually) expect path to exiftool.exe is defined in Win paths environment. That being expected, I use executable name only (and parameters, of course) in lpCommandLine. For example:
exiftool.exe param1 param2 .. file1 file2
-obviously exiftool.exe doesn't contain spaces.
If (path to) called application would contain spaces, i.e. "Exif Tool.exe", then I couldn't use that approach -I expect, I would get error message "Exif is not recognized as internal/external command". In that case, I would need to use 1st approach.

Bogdan

areohbee

If it's within a Lightroom plugin, then the problem is definitely the need for another wrapper of quotes around the whole kit'n'kaboodle.

Note: the extra wrapper of quotes must *not* be used if mac environment.