2 Replies Latest reply on Aug 4, 2010 5:39 PM by areohbee

    Question, Answer, & Feature Request - Building executable commands with spaces in everything.

    areohbee Level 5

      QUESTION:

      ---------------

      How do you build a proper command line string to pass to LrTasks.execute that has spaces in the path to the executable, and pass it options that include strings with spaces, passing it a target filename with spaces in the path and pipe the results to a file with spaces in the path - I'm about to lose my mind! - for example:

       

      local exeFile = LrPathUtils.child( _PLUGIN.path, "exiftool.exe" )

       

      local exeCmd = exeFile .. ' -G "' .. photoPath .. '" > "' .. exifPath .. '"' -- works with spaces in photo-path and/or the exif-path, but it fails if there are spaces in the exe-file path, and putting quotes around the exe-file path... - doesn't work.

       

      local pcallStatus, exitCode = LrTasks.pcall( LrTasks.execute, exeCmd ) -- not sure how much the pcall wrapper helps here, but its cheap insurance, I guess.

       

      ANSWER:

      ------------

       

      This works:

       

      local exeCmd = '""' .. exeFile .. '" -G "' .. photoPath .. '" > "' .. exifPath .. '""' -- darn hard to read in this font, but the idea is to put quotes around the whole thing: including the redirection, and the various paths.

       

       

      AND FEATURE REQUEST:

      ---------------------------------

      A command executer that handles spaces without even blinking, for example:

       

      local status, cmdExecuted[, output] = LrTasks.executeSpacesOk {

           executable = "C:\My Program Files\Some really cool app.exe",

           params = { '-G', "C:\My Data Files\Some really cool data.dat" },

           redirect = "C:\My Data Files\Some really cool results.txt", -- optional

      }

       

      Return the status of the execution, the actual command executed for debugging & learning, and if redirect is omitted, then the output is returned as a string, otherwise the output is sent to the specified redirect file.

       

      At a minimum - document LrTasks.execute space considerations in API and/or SDK docs.

       

      I wish Microsoft were the ones to solve this - its been a pet peeve for decades. Still, Adobe could help out big-time.

       

      Thanks,

      Rob