How can I pipe stderr, and not stdout?

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

    You can use the rc shell.

    First install the package (it's less than 1 MB).

    This an example of how you would discard standard output and pipe standard error to grep in rc:

    find /proc/ >[1] /dev/null |[2] grep task
    

    You can do it without leaving Bash:

    rc -c 'find /proc/ >[1] /dev/null |[2] grep task'
    

    As you may have noticed, you can specify which file descriptor you want piped by using brackets after the pipe.

    Standard file descriptors are numerated as such:

    • 0 : Standard input
    • 1 : Standard output
    • 2 : Standard error

提交回复
热议问题