0

In awesome 3.5, I used to have custom widgets relying in awful.util.pread(). In awesome 4.0, I was instructed to use awful.spawn.easy_async() instead

I tried to replace this:

local cmd = "echo 5555"
local ret = "5"
ret = awful.util.pread(cmd)

-- ret contains 5555

With this:

local cmd = {"bash", "-c", "echo 5555"}
local ret = "5"
awful.spawn.easy_async(cmd, function(stdout, stderr, reason, exit_code)
    ret = stdout
end)

-- ret contains 5

The variable ret remains unchanged. How can I reproduce the behavior of awful.util.pread() using awful.spawn functions?

Lem
  • 1
  • async means asynchronous, without knowing much about awesome, I would say you should *use* stdout *inside* the async block of code. instead of assigning it to a variable to be used outside of it, which will not work – Camusensei Mar 19 '17 at 21:00

1 Answers1

0

easy_async being asynchronous, so you should call a function inside the callback, assignments won't persist:

local cmd = {"bash", "-c", "echo 5555"}
awful.spawn.easy_async(cmd, function(stdout, stderr, reason, exit_code)
  naughty.notify { text = "output is " .. stdout }
end)
-- the anonymous function has not been called yet when this comment is reached
Camusensei
  • 1,475
  • 12
  • 20