You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用XMobar的BatteryP插件-a选项触发waitForProcess错误

Xmobar执行命令时出现waitForProcess错误的解决思路

问题情况

用xmobar.hs配置文件时,只要电池电量低于100%(为测试设置的阈值),状态栏就会弹出错误:

error: waitForProcess: does not exist (No child processes)

但实际上命令是执行成功的——比如date > ~/battery.out确实生成了文件,内容也完全符合预期。之前尝试实现可点击工作区时,也碰到了一模一样的错误。

我的配置文件

Xmonad配置(~/.config/xmonad/xmonad.hs)

import XMonad
import XMonad.Hooks.EwmhDesktops
import XMonad.Hooks.StatusBar
import XMonad.Hooks.StatusBar.PP

--spawn "xset dpms 0 0 0" >> -- Screensaver

main :: IO ()
main = xmonad
     . ewmhFullscreen
     . ewmh
     . withEasySB (statusBarProp (unwords ["xmobar", xmobarhs]) (pure def)) toggleStrutsKey
     $ myConfig
     where
       toggleStrutsKey XConfig { modMask = m } = (m, xK_b)
       xmobarhs = "~/.config/xmobar/xmobar.hs"

myConfig = def
    { terminal = "urxvt"
    , modMask = mod4Mask
    }

Xmobar配置(~/.config/xmobar/xmobar.hs,不是xmobarrc)

import Xmobar

main :: IO ()
main = xmobar defaultConfig {
       overrideRedirect = False
       , bgColor  = "#1f222d"
       , fgColor  = "#f8f8f2"
       , position = BottomSize L 100{- reduce this to put system tray -} 25
       , commands = [ Run $ BatteryP ["BAT0"]
                                     ["--template", "<acstatus><left>(<timeleft>)",
                                     "--", "-P",
                                     "-a", "date > ~/battery.out",{-¹-}
                                     "-A", "100"] 50 -- the "100" is to make the notification come up a few seconds after I've unplugged the power on a 100% charged battery
                    ]
       , sepChar  = "%"
       , alignSep = "}{"
       , template = "%battery%"
       }

注:原本打算把date > ~/battery.out换成notify-send -u critical 'Battery running out!!',但测试后发现不是notify-send本身的问题。

解决方法

这个错误的根源是:xmobar执行-a这类触发命令时,会默认尝试等待命令进程结束,但如果命令用到了shell的特性(比如重定向>、管道|),直接传字符串的话,xmobar找不到对应的独立进程,就会报这个错。

解决办法很简单,把命令用sh -c包裹起来,让shell去解析执行完整命令:

  1. 把电池触发命令改成:
"-a", "sh -c 'date > ~/battery.out'",
  1. 如果要用notify-send,改成:
"-a", "sh -c 'notify-send -u critical \"Battery running out!!\"'",

至于可点击工作区的问题,本质也是一样的——所有需要shell解析的点击命令,都要套一层sh -c,这样xmobar就能正确处理进程等待,不会再报错。

内容的提问来源于stack exchange,提问作者Enlico

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 22:55:08