lib/dtutils/file - reverted io_popen and os_execute wrappers as

lib/dtutils/system   they don't work in this situation (no control
                     over the input strings)
This commit is contained in:
Bill Ferguson
2024-07-13 12:46:34 -04:00
parent 7c93868bf0
commit 9f423eeef3
2 changed files with 15 additions and 66 deletions

View File

@@ -51,7 +51,7 @@ function dtutils_system.external_command(command)
local result = nil
if dt.configuration.running_os == "windows" then
result = dtutils_system.windows_command(ds.sanitize(command))
result = dtutils_system.windows_command(command)
else
result = dt.control.execute(command)
end
@@ -78,20 +78,20 @@ dtutils_system.libdoc.functions["windows_command"] = {
Copyright = [[]],
}
local function quote_windows_command(command)
local function _quote_windows_command(command)
return "\"" .. command .. "\""
end
function dtutils_system.windows_command(command)
local result = 1
local fname = ds.sanitize(dt.configuration.tmp_dir .. "/run_command.bat")
local fname = dt.configuration.tmp_dir .. "/run_command.bat"
local file = io.open(fname, "w")
if file then
dt.print_log("opened file")
command = string.gsub(command, "%%", "%%%%") -- escape % from windows shell
command = quote_windows_command(command)
command = _quote_windows_command(command)
file:write(command)
file:close()
@@ -124,6 +124,7 @@ dtutils_system.libdoc.functions["launch_default_app"] = {
License = [[]],
Copyright = [[]],
}
function dtutils_system.launch_default_app(path)
local open_cmd = "xdg-open "
if (dt.configuration.running_os == "windows") then
@@ -134,56 +135,4 @@ function dtutils_system.launch_default_app(path)
return dtutils_system.external_command(open_cmd .. path)
end
dtutils_system.libdoc.functions["os_execute"] = {
Name = [[os_execute]],
Synopsis = [[wrapper around the lua os.execute function]],
Usage = [[local dsys = require "lib/dtutils.file"
result = dsys.os_execute(cmd)
cmd - string - a command to execute on the operating system]],
Description = [[os_execute wraps the lua os.execute system call to provide
correct sanitization of windows commands]],
Return_Value = [[see the lua os.execute documentation]],
Limitations = [[]],
Example = [[]],
See_Also = [[]],
Reference = [[]],
License = [[]],
Copyright = [[]],
}
function dtutils_system.os_execute(cmd)
if dt.configuration.running_os == "windows" then
cmd = quote_windows_command(cmd)
end
return os.execute(cmd)
end
dtutils_system.libdoc.functions["io_popen"] = {
Name = [[io_popen]],
Synopsis = [[wrapper around the lua io.popen function]],
Usage = [[local dsys = require "lib/dtutils.file"
result = dsys.io_popen(cmd)
cmd - string - a command to execute and attach to]],
Description = [[io_popen wraps the lua io.popen system call to provide
correct sanitization of windows commands]],
Return_Value = [[see the lua io.popen documentation]],
Limitations = [[]],
Example = [[]],
See_Also = [[]],
Reference = [[]],
License = [[]],
Copyright = [[]],
}
function dtutils_system.io_popen(cmd)
if dt.configuration.running_os == "windows" then
cmd = quote_windows_command(cmd)
end
return io.popen(cmd)
end
return dtutils_system