Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
    
It should be noted that the &2>1 syntax is bash specific. For instanche in tcsh I would write |&. –  UncleZeiv Oct 5 '11 at 10:09
add comment

4 Answers

up vote 8 down vote accepted

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.

share|improve this answer
add comment

You need to redirect STDERR to STDOUT for all the commands. Then you can pipe it all into myprogram.

( make clean 2>&1 && make DISABLE_ID3TAG=1 CFLAGS="-O2 -DNDEBUG -W64" 2>&1 ) | myprogram
share|improve this answer
add comment
(make clean && make DISABLE_ID3TAG=1 CFLAGS="-O2 -DNDEBUG -W64") 2>&1 | myprogram
share|improve this answer
add comment

Depending on the complexity of myprogram, you could also try passing your make op to the myprogram, wherein you read the stdout and stderr as separate stream.

It depends on how complicated you want to make myprogram.

The main advantage is being able to handle stdout and stderr independently instead of lumped together.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.