I was using scons(python build tool) which calls gcc to build a file, like this:
$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.
Then I try to save all output to a file. I suppose the error messages are in stderr, so I try to redirect fd=2 to fd=1 like this:
$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
But seems error1 only contains information of "scons" command itself. All gcc error messages are still on screen, not saved in "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.
So how to make all scons called progrems re-direct their fd=2 to fd=1? Or this is a limitation of shell redirection that only the top caller's stream could be redirected?