linux g++ compiler redirect stderr and stdout creates empty file

China☆狼群 提交于 2021-02-07 06:54:15

问题


I am redirecting the g++ compiler output(both stderr and stdout) to a file on linux. But it is creating an empty file.

I read in some other post that stdout is not flushed after every line. Thats ok, but what about stderr. In my case there are compilation errors running several screens. So, I am interested in stderr output. There is no stdout output created.

 g++ -c -I ~/cplusplus/boost_1_37_0/boost_1_37_0/ -I 
~/cplusplus/niVxWorksDeliver/TEES/ Algorithms.cpp 2> output

The above command creates an empty file named "output". The following command reports invalid null command.

 g++ -c -I ~/cplusplus/boost_1_37_0/boost_1_37_0/ -I    
~/cplusplus/niVxWorksDeliver/TEES/ Algorithms.cpp &> output
Invalid null command.

回答1:


One of your comments betrays that you are not using bash. You're using csh or tcsh. In that case, you can redirect all output (including standard error) like this:

g++ -c Algorithms.cpp >& output

For more csh redirection syntax, I have a useful link bookmarked. Note that csh redirection syntax is not as fluent as bash syntax. You can do more in bash than you can in csh.




回答2:


You might try this:

sh/bash/zsh version:

g++ -c -I ~/cplusplus/boost_1_37_0/boost_1_37_0/ \
       -I ~/cplusplus/niVxWorksDeliver/TEES/ \
       Algorithms.cpp > output 2>&1

csh or tcsh version:

g++ -c -I ~/cplusplus/boost_1_37_0/boost_1_37_0/ \
       -I ~/cplusplus/niVxWorksDeliver/TEES/ \
       Algorithms.cpp >& output



回答3:


"No news is good news" -- does your command even produce any output? When there are no errors, g++ won't print out anything!



来源:https://stackoverflow.com/questions/578438/linux-g-compiler-redirect-stderr-and-stdout-creates-empty-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!