Why is vi showing color commands in captured output?


New Member
Hi All,

I took an update to Ubuntu recently (now on 18.04.5 LTS), and I notice that when I capture some output (like from a Maven build) to a file and then vi that file, I see all the color commands in the editor. That's definitely new, and not sure what's driving it. Google searches aren't helping since those special characters are mostly ignored. :confused:

So specifically, I run mvn package > build.out 2>&1, and then vi build.out after it's finished. And my editor looks like this:

Downloading from snapshots: https://our.servers.com/artifactory...ge/parent/101.0.0-SNAPSHOT/maven-metadata.xml
Progress (1): 606 B^M ^MDownloaded from snapshots: https://our.servers.com/artifactory...ge/parent/101.0.0-SNAPSHOT/maven-metadata.xml (606 B at 92 B/s)
WARNING^[[m] Some problems were encountered while building the effective model for com.company.barge:conn:jar:101.0.0-SNAPSHOT
[^[[1;33mWARNING^[[m] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 34, column 12
[^[[1;33mWARNING^[[m] It is highly recommended to fix these problems because they threaten the stability of your build.

Any idea what might be driving that? Thanks in advance.


Well-Known Member
Looks like mvn is injecting ANSI color codes into the output. I do this with some of my scripts to make the fast moving output easier to read / find / focus on a particular string. This can make the output easier to read, though it can pollute the output if you're saving it and what you view it in doesn't handle it properly.

There is sed magic and other tools that can help you strip them. Given they appear to be wrapping it up a bit seems odd and make cause more difficulty in removing them.
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Staff online

Members online