【发布时间】:2017-02-17 09:57:03
【问题描述】:
我使用的是 scons(python build tool),它调用 gcc 来构建文件,如下所示:
$scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o 1.o -c 1.cpp
1.cpp:20:5: error: no matching function for call to 'g'
g(&obj2);
^
1.cpp:12:6: note: candidate function not viable: no known conversion from 'B *' to 'A &' for 1st argument; remove &
void g(A&a){
^
1 error generated.
scons: *** [1.o] Error 1
scons: building terminated because of errors.
然后我尝试将所有输出保存到文件中。我想错误消息在 stderr 中,所以我尝试像这样将 fd=2 重定向到 fd=1:
$scons 2>&1 >error1
1.cpp:20:5: error: no matching function for call to 'g'
g(&obj2);
^
1.cpp:12:6: note: candidate function not viable: no known conversion from 'B *' to 'A &' for 1st argument; remove &
void g(A&a){
^
1 error generated.
scons: *** [1.o] Error 1
但似乎 error1 只包含“scons”命令本身的信息。所有 gcc 错误消息仍在屏幕上,未保存在“error1”中
$cat error1
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o 1.o -c 1.cpp
scons: building terminated because of errors.
那么如何让所有名为 progrem 的 scon 将它们的 fd=2 重定向到 fd=1?或者这是shell重定向的限制,只能重定向顶级调用者的流?
【问题讨论】:
-
BashFAQ #55 似乎非常中肯。
-
你也可以看到这篇文章:In the shell, what does 2>&1 mean?
-
我还没有通读所有答案,但那里的问题似乎没有涵盖重定向之间的排序——这有点相关。
标签: shell redirect gcc stdout stderr