How to save color output (stdout and stderr) for cmd scripts from powershell?

We have build scripts for cmd. For example, one of them is displayed here.

Colored output of build script from cmd

When I run the same commands on PS, it displays everything in red (possibly because it is for error output).

Red output of powershell

Is there any way to save colors?

+8
cmd powershell
source share
2 answers

At first I did not think that it was possible.

But after a bit of searching, I found this blog post, Painted console screen capture in HTML and RTF .

You can use the PowerShell script from there to create what you need.

+2
source share

I'm not sure if this will work, but if you don't mind redirecting stderr to stdout, PowerShell will not try to color all red. To do this, simply add 2> & 1 when running your cmd script, for example.

build.cmd 2>&1 
+1
source share

All Articles