7

I find that sometimes, ANSI escaping chars in mvn output prevents me to do this search with grep:

mvn | grep -P "\[INFO\]"

I have to use "\[.*INFO.*\]" to get results.

How to disable processing the ANSI escaping chars? I think there is some config for this?

2 Answers2

10

There's also --batch-mode (-B) for mvn which makes the output more suitable for e.g. CI or searches likes this as it's more automated.

Or, a generic solution, strip ANSI colors in any command by using ansi2txt tool, which is part of colorized-logs package:

mvn | ansi2txt | grep -P "\[INFO\]"
Destroy666
  • 12,350
6

Seems mvn has a config of -Dstyle.color=auto to ignore the ANSI color escaping chars so that I don't need to alter the pattern in my script to add .*.

# define an alias including the color settings
$ alias mvn='/opt/data/maven/bin/mvn -Dstyle.color=auto'

use the alias in the script

$ mvn | grep -P "[INFO]" [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.132 s [INFO] Finished at: 2023-05-25T14:05:13+03:00 [INFO] ------------------------------------------------------------------------