在Makefile规则中重定向stdout和stderr

Xya*_*and 18 linux bash shell makefile pipe

我想将脚本的输出重定向到另一个程序.我通常会使用这两种形式做的事情:

 python test.py 2>&1 | pyrg
 python test.py |& pyrg
Run Code Online (Sandbox Code Playgroud)

我的问题是它在makefile中不起作用:

[Makefile]
test:
    python test.py 2>&1 | pyrg [doesn't work]
Run Code Online (Sandbox Code Playgroud)

我希望避免编写一个完成工作的脚本文件.

编辑:

这似乎是一个pyrg问题:

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
Run Code Online (Sandbox Code Playgroud)

这对我来说是一个糟糕的解决方案,因为cat在测试失败的情况下我永远不会参与其中(一切都在Makefile规则中)

Luc*_*cas 8

我偶然发现了同样的问题并对答案不满意.我有一个TLBN在测试用例上失败的二进制文件example2.TLBN.

这是我的make文件首先查看的内容.

make:
     ./TLBN example2.TLBN > ex2_output.txt
Run Code Online (Sandbox Code Playgroud)

哪个失败了我正在预期的错误消息并停止make过程.

这是我的修复:

make:
    -./TLBN example2.TLBN > ex2_output.txt 2>&1
Run Code Online (Sandbox Code Playgroud)

注意-在行的开头告诉make忽略对stderr的任何输出.

希望这有助于有类似问题的人.


Xya*_*and 4

它没有解释为什么直接的方法不起作用,但它确实有效:

[Makefile]
test: 
    python test.py >test.out 2>&1; pyrg <test.out
Run Code Online (Sandbox Code Playgroud)