Is there a way to capture console output from a process with color formatting data? Currently I am capturing just the text output with:
ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/C", "mvn dependency:resolve");
// mvn dependency:resolve is an example of a process that outputs color
Process p = builder.start();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null)
{
System.out.println(line);
}
But I can't find a way to capture color data for this text. The colored text does not seem to start with any special character or anything.
I am printing this captured text to UI for the user to see log of this process but it is hard to read so I would like to copy the colors from the console.
Here is an example of how it can be done in Go, but can this be done in Java?
This application is going to be run on Windows but it would be great if it could also work on Linux or MacOS by reading the same color data from Shell or Bash.