For example, when I’m writing program that outputs text to stdout and uses colors (via escape sequences), I would like to disable those colors if output goes to other program (like less, grep) or to file, since color codes mess up the output.
Is it possible to do it from Java process?
I solved it in a following way (described here):
System.console() will return
Consoleobject, if there is some terminal connected to application, and it will returnnullif you pipe output into other app or save it to file.Thus it becomes a simple check:
(tested on Linux Mint 10)