How to get color output from `mix compile` invoked via `System.cmd`?

I have a mix task that runs invokes mix test with various environment variables (MIX_ENV=xxx). The line for the invocation essentially looks like this:

System.cmd("mix", ["test", "--color"], into:, :line))

That gives me colorized output for the tests.

However, if any compiling takes place before running the tests, the output is not colorized. So I might get warnings but they won’t be yellow.

This can also be reproduced by replacing the invocation of mix test directly with mix compile.

How can I get the output fully colorized?

I had to solve for this at one point and I can’t readily find the reference I cited, but this appears to be working for me:

System.cmd("elixir", ["--erl", "-elixir ansi_enabled true", "-S", "mix", "test"], into:, :line))

In my case I was using it as part of mix cmd like so:

mix cmd --app ... elixir --erl \"-elixir ansi_enabled true\" -S mix ...

Saweet! That did the trick. Thanks a bunch!