开发者

G++ and sed pipeline

I would like to replace all "no" by "on" in the console output of g++. I tried

$ g++ | sed -e 's/no/on/g'

But it shows

i686-apple-darwin9-g++-4.0.1: no input files

instead of

i686-app开发者_运维技巧le-darwin9-g++-4.0.1: on input files


The message is arriving on the standard error, but the shell pipe operator connects the standard output of one process to the standard input of the next.

To reroute stderr, use

$ g++ 2>&1 | sed -e 's/no/on/g'

or

$ g++ |& sed -e 's/no/on/g'

to get

g++: on input files
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜