How can I pipe stderr, and not stdout?

后端 未结 11 1298
-上瘾入骨i
-上瘾入骨i 2020-11-22 03:28

I have a program that writes information to stdout and stderr, and I need to process the stderr with grep, leaving

11条回答
  •  春和景丽
    2020-11-22 04:16

    This will redirect command1 stderr to command2 stdin, while leaving command1 stdout as is.

    exec 3>&1
    command1 2>&1 >&3 3>&- | command2 3>&-
    exec 3>&-
    

    Taken from LDP

提交回复
热议问题