【问题标题】:How to pipe stderr to notify-send?如何通过管道将标准错误发送到通知发送?
【发布时间】:2020-08-20 17:52:36
【问题描述】:

我使用键绑定运行程序,它们本身可以调用 dmenu 并在后台执行操作。我很想将stderr 传送到notify-send 并在出现故障时收到通知。

这些程序不是从终端仿真器调用的,主要是sxhkd 加上xdg-open 替代jaro

以这个例子为例:

$ ls /root
"/root": Permission denied (os error 13)
$ ls /root 2> /dev/null
$

如果我有一个 sxhkd 条目

super + Return
  ls /root

如何让它输出 stderr 到通知?

【问题讨论】:

    标签: shell pipe stderr


    【解决方案1】:

    创建脚本notify-pipe:

    #!/usr/bin/env sh
    
    read notification
    notify-send "Command Failed" "$notification" "$@"
    

    并将stderr 传递给stdout

    $ ls /root  2>&1| notify-pipe
    

    可能的增强功能:bash get command that was used before pipe symbol 以获取通知摘要中的命令。

    感谢您的帮助,罗恩。

    【讨论】:

      【解决方案2】:

      notify-send 不适用于piping

      但是,您可以尝试: sudo pip install notify-pipe

      接受piping

      请看这里:https://github.com/ron7/notify-pipe

      您可以通过管道将stderr 发送到stdout 并将其发送到通知管道

      command 2>&1|notify-pipe
      

      【讨论】:

        猜你喜欢
        • 2013-10-18
        • 2014-09-25
        • 1970-01-01
        • 2022-01-24
        • 1970-01-01
        • 2014-03-27
        • 1970-01-01
        • 2018-03-25
        • 1970-01-01
        相关资源
        最近更新 更多