Skip to main content

Redirect standard error of one command to standard input of another command [Resolved]

I wish to redirect standard error of one command to standard input of another command like

g++ filename.cpp 'redirection' less

Question Credit: vib_29
Question Reference
Asked March 17, 2019
Posted Under: Unix Linux
19 views
1 Answers

You can use pipe to do that

command1 2>&1 >/dev/null | command2

It will redirect the standard error stream of the first command to the standard input stream of the second command while discarding the standard output stream of command1.

The redirections are done in order:

  1. command1 2>&1 will redirect file descriptor 2 (standard error) to wherever file descriptor 1 (standard output) is connected.

  2. >/dev/null (the same as 1>/dev/null) will redirect standard output to /dev/null.

In your case:

g++ filename.cpp 2>&1 >/dev/null | less

credit: Kusalananda
Answered March 17, 2019
Your Answer