Copy link to clipboard
Copied
I'm trying to fix an existing plug-in written by someone else, Teekesselchen, which executes exiftool from the plug-in's directory. There is a bug on Windows on my machine where it does not execute exiftool, because my Windows user name has a space in it. The plug-in does have logging, fortunately, and I have used MS Devstudio to look at it.
Here is the existing code :
function Util.getExifToolCmd(parameters) if WIN_ENV then return LrPathUtils.child( _PLUGIN.path, "exiftool.exe") .. " " .. parameters else -- must be mac return "'" .. LrPathUtils.child( _PLUGIN.path, "exiftool") .. "' " .. parameters end end
local function getExifToolData(settings) local parameters = settings.exifToolParameters local doLog = settings.activateLogging local cmd = Util.getExifToolCmd(parameters) local temp = Util.getTempPath("teekesselchen_exif.tmp") local logger = _G.logger return function(photo) local path = photo:getRawMetadata("path") local cmdLine = cmd .. ' "' .. path .. '" > "' .. temp .. '"' local value if LrTasks.execute(cmdLine) == 0 then value = LrFileUtils.readFile(temp) if doLog then logger:debug("getExifToolData data: " .. value) end else if doLog then logger:debug("getExifToolData error for : " .. cmdLine) end end -- nil is not a valid key, thus, we take a dummy value if not value then value = "~exifTool#" end return value end end
When I ran it for the first time under MS Dev studio, I saw this in the debug output :
L: teekesselchen DEBUG getExifToolData error for : C:\Users\Julien Pierre\AppData\Roaming\Adobe\Lightroom\Modules\teekesselchen.lrplugin\exiftool.exe -ShutterCount "D:\Documents\Pictures\2021\05\2021-05-06_21.DNG" > "C:\Users\Julien Pierre\AppData\Local\Temp\teekesselchen_exif.tmp"
As you can see, the path to exiftool.exe is not quoted, and that's why Windows can't find it.
I tried to fix it with the following change, to quote the exiftool location :
if WIN_ENV then -- return LrPathUtils.child( _PLUGIN.path, "exiftool.exe") .. " " .. parameters return '"' .. LrPathUtils.child( _PLUGIN.path, "exiftool.exe") .. '"' .. "' " .. parameters else
This still did not work, unfortunately. The debug log entry shows :
L: teekesselchen DEBUG getExifToolData error for : "C:\Users\Julien Pierre\AppData\Roaming\Adobe\Lightroom\Modules\teekesselchen.lrplugin\exiftool.exe"' -ShutterCount "D:\Documents\Pictures\2021\05\2021-05-06_21.DNG" > "C:\Users\Julien Pierre\AppData\Local\Temp\teekesselchen_exif.tmp"
If I paste this command line into a Windows command-terminal (CMD.EXE), the command-line executes just fine. It only fails from Lightroom, somehow.
I have tried copying exiftool to another location that does not have a space in it, and this works as follows :
function Util.getExifToolCmd(parameters) if WIN_ENV then -- return LrPathUtils.child( _PLUGIN.path, "exiftool.exe") .. " " .. parameters -- return '"' .. LrPathUtils.child( _PLUGIN.path, "exiftool.exe") .. '"' .. "' " .. parameters return "D:/Downloads/Exiftool/exiftool.exe " .. parameters else -- must be mac return "'" .. LrPathUtils.child( _PLUGIN.path, "exiftool") .. "' " .. parameters end end
In this case the debug output is as expected :
L: teekesselchen DEBUG getExifToolData data: Shutter Count : 9616
However, no matter what I have tried, I can't make LRTasks.execute run exiftool from the plug-in's location at "C:\Users\Julien Pierre\AppData\Roaming\Adobe\Lightroom\Modules\teekesselchen.lrplugin\exiftool.exe".
I have spent many hours on this, trying various things like using forward slash instead of backslash, using escaped backslashes, using single quote around the whole path instead of double-quote - and absolutely nothing has worked ! I want it to work from the plug-in's location so I can contribute a fix back to the original author.
What's the magic trick to running a program from a location with a space in it with LRTasks.execute ? I read this thread, but was not able to figure it out.
Also read lua docs on string at https://www.lua.org/pil/2.4.html . But this would appear to be an issue with Lightroom, not Lua, as far as I can tell.
Any help on this would be greatly appreciated .
Copy link to clipboard
Copied
I found the solution shortly after this.
https://app.assembla.com/wiki/show/lrdevplugin/Mac_and_Windows_Differences
Copy link to clipboard
Copied
For the benefit of others, here is the working code :
function Util.getExifToolCmd(parameters)
if WIN_ENV then
return '"' .. LrPathUtils.child( _PLUGIN.path, "exiftool.exe") .. '" ' .. parameters
else
-- must be mac
return "'" .. LrPathUtils.child( _PLUGIN.path, "exiftool") .. "' " .. parameters
end
end
local function getExifToolData(settings)
local parameters = settings.exifToolParameters
local doLog = settings.activateLogging
local cmd = Util.getExifToolCmd(parameters)
local temp = Util.getTempPath("teekesselchen_exif.tmp")
local logger = _G.logger
return function(photo)
local path = photo:getRawMetadata("path")
local cmdLine = cmd .. ' "' .. path .. '" > "' .. temp .. '"'
if WIN_ENV then cmdLine = '"' .. cmdLine .. '"' end
local value
if LrTasks.execute(cmdLine) == 0 then
value = LrFileUtils.readFile(temp)
if doLog then
logger:debug("getExifToolData data: " .. value)
end
else
if doLog then
logger:debug("getExifToolData error for : " .. cmdLine)
end
end
-- nil is not a valid key, thus, we take a dummy value
if not value then value = "~exifTool#" end
return value
end
end
Copy link to clipboard
Copied
Glad you found that "well known" idiom. There are posts about it in this forum, though they are much harder to find after Adobe merged the LR SDK forum with the main LR forum last year.