1

Linux 中有一些命令可以选择保留颜色而不管 IO 重定向如何,例如:

| grep --color=always

有没有办法为任何自定义程序保留输出重定向的颜色?

在我的特定示例中,我使用带有颜色输出的 cmake,它被重定向到 sed 以突出显示警告和错误(使用http://shawnwilsher.com/2008/12/highlight-warnings-in-make/)。

4

1 回答 1

0

Programs decide to turn coloring sequences off by checking if file descriptor 1 points to /dev/stdout. If there is no option to override that check, you have to 'be the terminal' for the program.

I found InterceptTTY which is supposed to do exactly that, although i have no experience with it.

于 2012-08-31T11:16:04.237 回答