How can I pipe stderr, and not stdout?

后端 未结 11 1174
-上瘾入骨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:05

    I just came up with a solution for sending stdout to one command and stderr to another, using named pipes.

    Here goes.

    mkfifo stdout-target
    mkfifo stderr-target
    cat < stdout-target | command-for-stdout &
    cat < stderr-target | command-for-stderr &
    main-command 1>stdout-target 2>stderr-target
    

    It's probably a good idea to remove the named pipes afterward.

提交回复
热议问题