在令人敬畏的3.5中,我曾经有过依赖于awful.util.pread()的自定义小部件。在令人敬畏的4.0中,我被指示使用awful.spawn.easy_async()代替
我试图替换它:
local cmd = "echo 5555"
local ret = "5"
ret = awful.util.pread(cmd)
-- ret contains 5555
有了这个:
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
变量ret保持不变。 如何使用awful.spawn函数重现awful.util.pread()的行为?
答案 0 :(得分:0)
easy_async是异步的,所以你应该在回调中调用函数,分配不会持久:
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