Skip to content

Commit 2f330ea

Browse files
committed
lib/dtutils/system - added wrapper functions io_popen and os_execute
to wrap io.popen and os.execute system calls respectively. These wrapper functions provide the necessary quoting on windows to get handle strings with spaces and special characters.
1 parent c3ce8d5 commit 2f330ea

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

lib/dtutils/system.lua

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,55 @@ function dtutils_system.launch_default_app(path)
129129
end
130130

131131

132+
dtutils_system.libdoc.functions["os_execute"] = {
133+
Name = [[os_execute]],
134+
Synopsis = [[wrapper around the lua os.execute function]],
135+
Usage = [[local dsys = require "lib/dtutils.file"
136+
137+
result = dsys.os_execute(cmd)
138+
cmd - string - a command to execute on the operating system]],
139+
Description = [[os_execute wraps the lua os.execute system call to provide
140+
correct sanitization of windows commands]],
141+
Return_Value = [[see the lua os.execute documentation]],
142+
Limitations = [[]],
143+
Example = [[]],
144+
See_Also = [[]],
145+
Reference = [[]],
146+
License = [[]],
147+
Copyright = [[]],
148+
}
149+
150+
function dtutils_system.os_execute(cmd)
151+
if _scripts_install.dt.configuration.running_os == "windows" then
152+
cmd = "\"" .. cmd .. "\""
153+
end
154+
return os.execute(cmd)
155+
end
156+
157+
dtutils_system.libdoc.functions["io_popen"] = {
158+
Name = [[io_popen]],
159+
Synopsis = [[wrapper around the lua io.popen function]],
160+
Usage = [[local dsys = require "lib/dtutils.file"
161+
162+
result = dsys.io_popen(cmd)
163+
cmd - string - a command to execute and attach to]],
164+
Description = [[io_popen wraps the lua io.popen system call to provide
165+
correct sanitization of windows commands]],
166+
Return_Value = [[see the lua io.popen documentation]],
167+
Limitations = [[]],
168+
Example = [[]],
169+
See_Also = [[]],
170+
Reference = [[]],
171+
License = [[]],
172+
Copyright = [[]],
173+
}
174+
175+
function dtutils_system.io_popen(cmd)
176+
if _scripts_install.dt.configuration.running_os == "windows" then
177+
cmd = "\"" .. cmd .. "\""
178+
end
179+
return io.popen(cmd)
180+
end
181+
182+
132183
return dtutils_system

0 commit comments

Comments
 (0)