2012-08-01 427 views
15

我想将脚本的输出重定向到不同的程序。这是我通常会做使用这两种形式:在Makefile规则中重定向标准输出和stderr

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

我的问题是,它并没有从一个makefile内工作:

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

我想避免编写一个脚本文件,它做的工作。

编辑:

这似乎是一个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 

这对我来说是一个坏的解决方案,因为我从来没有到cat部位在试验失败的情况下(一切在Makefile规则里面)

+4

这应该工作。 'make'将整行传递给'/ bin/sh'来解释,所以任何这个shell(不需要是你的用户shell)都可以理解。 – 2012-08-01 08:26:11

+2

究竟是如何不起作用?尝试在makefile中的某处设置'export SHELL:=/bin/bash'。 – 2012-08-01 08:34:26

+0

第二个命令运行,就好像它没有收到任何来自'stdin'的输入。它实际上在第一个之前运行。使用'||'而不是'|'来维护顺序,但又一次'pyrg'没有得到输入。 – Xyand 2012-08-01 08:51:09

回答

3

这并不能解释为什么直接的方法不起作用,但它的确有用:

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

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

这是我的make文件首先看到的。

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

与错误信息,我期待并暂停make进程失败。

这是我的解决办法:

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

注意-在这告诉make忽略任何输出到stderr行的开头。

希望这可以帮助有类似问题的人。