【问题标题】:Replacement for awful.util.pread in awesome 4.0在 awesome 4.0 中替换 awesome.util.pread
【发布时间】:2017-03-20 16:41:58
【问题描述】:

在真棒 3.5 中,我曾经有依赖于可怕.util.pread() 的自定义小部件。在真棒 4.0 中,我被指示使用 awesome.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 保持不变。 如何使用可怕的.spawn 函数重现可怕的.util.pread() 的行为?

【问题讨论】:

  • async 是异步的意思,在不太了解 awesome 的情况下,我会说你应该使用 stdout inside async 代码块。而不是将其分配给要在其外部使用的变量,这是行不通的

标签: awesome-wm


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-01
    • 1970-01-01
    • 2015-02-28
    • 1970-01-01
    • 2015-11-08
    • 2013-11-03
    相关资源
    最近更新 更多