外壳重定向:scons 调用 gcc,构建错误重定向不起作用



我正在使用scons(python build build tool),该(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

,但似乎错误1仅包含" 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的SCON重新指导其fd = 2 to fd = 1?否则这是外壳重定向的限制,只有顶级呼叫者的流才能重定向?

重定向是从左到右执行的,指的是其目的地的状态。

  • 2>&1 >error1执行以下操作顺序:

    1. fd 2指向操作启动时的任何目标fd 1(由于您将内容报告给屏幕上,所以这大概是您的终端)。

    2. fd 1指向文件error1

  • >error1 2>&1执行以下操作顺序:

    1. fd 1指向文件error1

    2. fd 2指向位置fd 1目前指向(因此,也是 file error1)。


因此,在2>&1 >error1情况下,仅FD 1(STDOUT) - 而不是FD 2(STDERR) - 指向error1,因为当调用2>&1时,FD 1定向到终端。

最新更新