我可以在处理时保持编译器输出的格式

Can I keep the formatting of the compiler output when handling it?

本文关键字:编译器 输出 格式 处理 我可以      更新时间:2023-10-16

每当我调用运行GCC时,它都会很好地格式化其输出(使文件名粗体,注意标签白色,错误标签红色等)。但是,当我想重定向并保持显示时,格式就消失了...

示例:

make                                    # The display is formatted
(...)
make |& tee >(xargs echo > example.out) # The display is not formatted
(...)

在保持原始显示格式时如何重定向输出?

文档说( File: gcc-6.info, Node: Diagnostic Message Formatting Options):

-fdiagnostics-color [=何时]

在诊断中使用颜色。何时neveralwaysauto。 默认值取决于编译器的配置方式,可以 在选项时为上述任何一个,或者never如果GCC_COLORS 环境变量在环境中不存在,auto 否则。auto意味着仅在标准错误时使用颜色 是终端。