lib/dtutils/system added local helper function quote_windows_command() to
wrap a windows command in quotes. Added a sanitize step
to windows_external_command() plus quote_windows_command()
to deal with all the windows username possibilities
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
local dtutils_system = {}
|
local dtutils_system = {}
|
||||||
|
|
||||||
local dt = require "darktable"
|
local dt = require "darktable"
|
||||||
|
local ds = require "lib/dtutils.string"
|
||||||
|
|
||||||
dtutils_system.libdoc = {
|
dtutils_system.libdoc = {
|
||||||
Name = [[dtutils.system]],
|
Name = [[dtutils.system]],
|
||||||
@@ -50,9 +51,9 @@ function dtutils_system.external_command(command)
|
|||||||
local result = nil
|
local result = nil
|
||||||
|
|
||||||
if dt.configuration.running_os == "windows" then
|
if dt.configuration.running_os == "windows" then
|
||||||
result = dtutils_system.windows_command(command)
|
result = dtutils_system.windows_command(ds.sanitize(command))
|
||||||
else
|
else
|
||||||
result = dt.control.execute(command)
|
result = dt.control.execute(ds.sanitize(command))
|
||||||
end
|
end
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@@ -77,15 +78,20 @@ dtutils_system.libdoc.functions["windows_command"] = {
|
|||||||
Copyright = [[]],
|
Copyright = [[]],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local function quote_windows_command(command)
|
||||||
|
return "\"" .. command .. "\""
|
||||||
|
end
|
||||||
|
|
||||||
function dtutils_system.windows_command(command)
|
function dtutils_system.windows_command(command)
|
||||||
local result = 1
|
local result = 1
|
||||||
|
|
||||||
local fname = dt.configuration.tmp_dir .. "/run_command.bat"
|
local fname = ds.sanitize(dt.configuration.tmp_dir .. "/run_command.bat")
|
||||||
|
|
||||||
local file = io.open(fname, "w")
|
local file = io.open(fname, "w")
|
||||||
if file then
|
if file then
|
||||||
dt.print_log("opened file")
|
dt.print_log("opened file")
|
||||||
command = string.gsub(command, "%%", "%%%%") -- escape % from windows shell
|
command = string.gsub(command, "%%", "%%%%") -- escape % from windows shell
|
||||||
|
command = quote_windows-command(command)
|
||||||
file:write(command)
|
file:write(command)
|
||||||
file:close()
|
file:close()
|
||||||
|
|
||||||
@@ -149,7 +155,7 @@ dtutils_system.libdoc.functions["os_execute"] = {
|
|||||||
|
|
||||||
function dtutils_system.os_execute(cmd)
|
function dtutils_system.os_execute(cmd)
|
||||||
if dt.configuration.running_os == "windows" then
|
if dt.configuration.running_os == "windows" then
|
||||||
cmd = "\"" .. cmd .. "\""
|
cmd = quote_windows_command(cmd)
|
||||||
end
|
end
|
||||||
return os.execute(cmd)
|
return os.execute(cmd)
|
||||||
end
|
end
|
||||||
@@ -174,7 +180,7 @@ dtutils_system.libdoc.functions["io_popen"] = {
|
|||||||
|
|
||||||
function dtutils_system.io_popen(cmd)
|
function dtutils_system.io_popen(cmd)
|
||||||
if dt.configuration.running_os == "windows" then
|
if dt.configuration.running_os == "windows" then
|
||||||
cmd = "\"" .. cmd .. "\""
|
cmd = quote_windows_command(cmd)
|
||||||
end
|
end
|
||||||
return io.popen(cmd)
|
return io.popen(cmd)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user