我使用scon(python构建工具)来调用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只包含“scon”命令本身的信息。所有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.那么,如何使所有被称为progrems的人将他们的fd=2重新定向到fd=1?或者这是shell重定向的限制,只有顶级调用方的流才能被重定向?
发布于 2017-02-17 01:52:01
重定向是从左到右执行的,它指的是其目的地的状态,即前一个方向完成执行时的状态。
2>&1 >error1按照以下操作顺序执行:1. FD 2 is pointed to whichever destination FD 1 was directed to when the operation started (since you're reporting that content is written to the screen, this is presumably your terminal).
2. FD 1 is pointed to the file `error1`.
>error1 2>&1按照以下操作顺序执行:1. FD 1 is pointed to the file `error1`
2. FD 2 is pointed to the location FD 1 presently points to (thus, _also_ the file `error1`).
因此,在2>&1 >error1情况下,只有FD 1 (stdout) --而不是FD 2 (stderr) --指向error1,因为当2>&1被调用时,FD 1是指向终端的。
https://stackoverflow.com/questions/42287981
复制相似问题