Piping stdout and stderr inside a Makefile rule

It doesn't explain why the straightforward approaches don't work, but it does the trick:

[Makefile]
test: 
    python test.py >test.out 2>&1; pyrg <test.out

I stumbled upon this question with the same problem and wasn't satisfied with the answer. I had a binary TLBN that failed on test case example2.TLBN.

This is what my make file looked at first.

make:
     ./TLBN example2.TLBN > ex2_output.txt

Which failed with the error message I was expecting and halting the make process.

This is my fix:

make:
    -./TLBN example2.TLBN > ex2_output.txt 2>&1

Note the - at the beginning of the line which tells make to ignore any output to stderr.

Hope this helps someone that has a similar problem.


Strangely, I had the same problem, and solved it like this:

check-errors:
    check-for-errors.sh &> errors.txt

I am not really sure why 2>&1 >errors.txt did not work here, but &> did