Java capture process output with color

The problem you are facing doesn't relate strictly to Java capability.

What happens is that many programs check whether stdin is a terminal or a pipe and generate output differently, dropping color formatting for example. Sometimes workaround exists directly by use of special option to force the generation of those color formatting 1.

If this is not available in the binary you are using, the apprently only solution is to write your own pseudo-tty making the targeted binary think it talks to a regular tty.

You can try to use the code presented here 2 or you can take a look at JetBrains/pty4j and see if you can tweak it to your needs.

java output color tty

Tags:

Java

Cmd