Search code examples
linuxbashshellmakefilepipe

Piping stdout and stderr inside a Makefile rule


I want to pipe the output of a script to a different program. Something I would normally do using these two forms:

 python test.py 2>&1 | pyrg
 python test.py |& pyrg

My problem is that it doesn't work from inside a makefile:

[Makefile]
test:
    python test.py 2>&1 | pyrg [doesn't work]

I wish to avoid writing a script file that does the work.

Edit:

This seems like a pyrg issue:

python test.py 2>&1 | tee test.out // Writes to the file both stderr and stdout
cat test.out | pyrg                // Works fine!
python test.py 2>&1 | pyrg         // pyrg behaves as if it got no input

This is a bad solution for me as I never get to the cat part in case of a test failure (everything is inside a Makefile rule)


Solution

  • 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