From f5e9aceebfc1e9ee4c8383b55d8190e27ad7f7db Mon Sep 17 00:00:00 2001 From: dvs1 Date: Sun, 20 Oct 2024 10:54:11 +1000 Subject: Tweak APT.exe so status works more reliably. --- apt-panopticommon.lua | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'apt-panopticommon.lua') diff --git a/apt-panopticommon.lua b/apt-panopticommon.lua index e31c22f..0939c3a 100644 --- a/apt-panopticommon.lua +++ b/apt-panopticommon.lua @@ -501,6 +501,8 @@ APT.readCmd = function(cmd) table.insert(result, l) end end + -- While this does return the same things as os.execute(), it's just as useless. + output:close() return result end @@ -590,23 +592,23 @@ APT.exe = function(c) I'm getting 7168 or 0. No idea what the fuck that is. local ok, rslt, status = os.execute(s) ]] - local f = APT.readCmd(self.cmd, 'r') + local f = APT.readCmd(self.cmd .. '; echo "$?"', 'r') -- The last line will be the command's returned status, collect everything else in result. - self.status = '' -- Otherwise the result starts with 0. + self.status = tonumber(f[#f]) + f[#f] = nil self.result = '\n' for i,l in ipairs(f) do self.result = self.result .. l .. "\n" end - f = APT.readCmd('echo "$?"', 'r') - for i,l in ipairs(f) do - self.status = tonumber(l) - if (137 == self.status) or (124 == self.status) then - print("timeout killed " .. self.status .. ' ' .. self.command) - E("timeout killed " .. self.status .. ' ' .. self.command) - elseif (0 ~= self.status) then - print("status |" .. self.status .. '| ' .. self.command) - E("status |" .. self.status .. '| ' .. self.command) - end + if (137 == self.status) or (124 == self.status) then + print("timeout killed " .. self.status .. ' ' .. self.command) + print('ERROR ' .. "timeout killed " .. self.status .. ' ' .. self.command) + elseif (nil == self.status) then + print("status |" .. "NIL" .. '| ' .. self.command) + E("status |" .. "NIL" .. '| ' .. self.command) + elseif (0 ~= self.status) then +-- print("status |" .. self.status .. '| ' .. self.command) + E("status |" .. self.status .. '| ' .. self.command) end return self end -- cgit v1.1