【发布时间】:2012-07-30 02:48:19
【问题描述】:
我想将脚本的输出通过管道传输到不同的程序。我通常会使用这两种形式做的事情:
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 规则内)
【问题讨论】:
-
这应该可以。
make将整行传递给/bin/sh进行解释,所以这个shell(不需要是你的用户shell)可以理解的任何东西。 -
到底怎么不工作?尝试在 makefile 中的某处设置
export SHELL := /bin/bash。 -
第二个命令运行时好像没有收到来自
stdin的任何输入。它实际上在第一个之前运行。使用||而不是|可以保持顺序,但pyrg再次没有得到输入。 -
@MaximYegorushkin,此设置有助于避免在使用
|&时出现错误。但它的行为仍然与我之前的评论一样。 -
程序的启动顺序无关紧要。即便如此,两者也会通过管道连接起来。
标签: linux bash shell makefile pipe