diff options
author | Alexander Yakushev <yakushev.alex@gmail.com> | 2012-02-13 21:17:41 +0200 |
---|---|---|
committer | Alexander Yakushev <yakushev.alex@gmail.com> | 2012-02-13 21:44:25 +0200 |
commit | 22583ad7dcd2237829e0072dfd018adeb4067496 (patch) | |
tree | 4a46a69b57c7e3efe24a33fcef336f8fae332181 | |
parent | a488a4f81eaa273d79d228b398dcfee153577e52 (diff) | |
download | awesompd-22583ad7dcd2237829e0072dfd018adeb4067496.tar.gz awesompd-22583ad7dcd2237829e0072dfd018adeb4067496.tar.bz2 |
Fixes in asyncshell
-rw-r--r-- | asyncshell.lua | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/asyncshell.lua b/asyncshell.lua index 63234c6..7510065 100644 --- a/asyncshell.lua +++ b/asyncshell.lua @@ -8,10 +8,11 @@ asyncshell = {} asyncshell.request_table = {} asyncshell.id_counter = 0 -asyncshell.file_template = '/tmp/asyncshellreq' +asyncshell.folder = "/tmp/asyncshell" +asyncshell.file_template = asyncshell.folder .. '/req' -os.execute('rm -f /tmp/myaw2.log') -local nprint = function(t) os.execute("echo '" .. t .. "' >> /tmp/myaw2.log") end +-- Create a directory for asynchell response files +os.execute("mkdir -p " .. asyncshell.folder) -- Returns next tag - unique identifier of the request local function next_id() @@ -21,16 +22,17 @@ end -- Sends an asynchronous request for an output of the shell command. -- @param command Command to be executed and taken output from --- @param callback Function of one argument to be called when the command finishes +-- @param callback Function to be called when the command finishes -- @return Request ID function asyncshell.request(command, callback) local id = next_id() local tmpfname = asyncshell.file_template .. id asyncshell.request_table[id] = {callback = callback} - local req = + local req = string.format("bash -c '%s > %s; " .. 'echo "asyncshell.deliver(%s)" | ' .. - "awesome-client'", string.gsub(command, "'", "'\\''"), tmpfname, id, tmpfname) + "awesome-client' 2> /dev/null", + string.gsub(command, "'", "'\\''"), tmpfname, id, tmpfname) awful.util.spawn(req) return id end @@ -40,7 +42,8 @@ end -- @param id Request ID -- @param output The output file of the shell command to be delievered function asyncshell.deliver(id) - if asyncshell.request_table[id] then + if asyncshell.request_table[id] and + asyncshell.request_table[id].callback then local output = io.open(asyncshell.file_template .. id, 'r') asyncshell.request_table[id].callback(output) end @@ -54,7 +57,8 @@ end function asyncshell.demand(command, timeout) local id = next_id() local tmpfname = asyncshell.file_template .. id - local f = io.popen(string.format("(%s > %s; echo asyncshell_done) & (sleep %s; echo asynchell_timeout)", + local f = io.popen(string.format("(%s > %s; echo asyncshell_done) & " .. + "(sleep %s; echo asynchell_timeout)", command, tmpfname, timeout)) local result = f:read("*line") if result == "asyncshell_done" then |