在AWE3.5中,我曾经使用依赖于awful.util.pread()的自定义小部件。在AWE4.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()的行为?
发布于 2017-03-20 16:41:58
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 reachedhttps://stackoverflow.com/questions/42885714
复制相似问题