Merge pull request #21 from vxcontrol/add-cmd-exec

add utils/system
This commit is contained in:
Dmitry Ng
2022-12-19 12:07:45 +03:00
committed by GitHub
2 changed files with 39 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
require("yaci")
require("strict")
local pp = require("pp")
local glue = require("glue")
CSystemInfo = newclass("CSystemInfo")
function CSystemInfo:print(...)
if self.is_debug then
local t = glue.pack(...)
for i, v in ipairs(t) do
t[i] = pp.format(v)
end
print(glue.unpack(t))
end
end
function CSystemInfo:init(is_debug)
self.is_debug = false
if type(is_debug) == "boolean" then
self.is_debug = is_debug
end
self:print("intialize CSystemInfo object")
end
function CSystemInfo:exec_cmd(cmd, raw)
self:print("cmd to exec: " .. tostring(cmd))
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
self:print("cmd output: " .. tostring(s))
if raw or raw == nil then return s end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
+1
View File
@@ -0,0 +1 @@
require("system.info")