linux – How to Send stderr to stdout with Pipe

command linelinuxmakepipestdout

I'm trying to capture all of the output of a build operation, and send it to myprogram. I seem to only be able to capture part of it. This is what I'm trying:

make clean && make DISABLE_ID3TAG=1 CFLAGS="-O2 -DNDEBUG -W64" | myprogram &2 > 1

I also tried:

make clean && make DISABLE_ID3TAG=1 CFLAGS="-O2 -DNDEBUG -W64" &2 > 1 | myprogram

Basically I want to send everything to stdout and then do something with that. Currently I'm only capturing part of the output, and the other part is going to the screen. How can I pipe everything to another program?

Best Answer

Since you have two commands, it would be better to use:

{ make clean && make DISABLE_ID3TAG=1 CFLAGS="-O2 -DNDEBUG -W64"; } 2>&1 | myprogram

Or

( make clean && make DISABLE_ID3TAG=1 CFLAGS="-O2 -DNDEBUG -W64" ) 2>&1 | myprogram

The make clean is not directing its output to the pipe, you will want to use either of the two above to let the shell redirect the output of both make calls as one.

Related Question