Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to preserve colored output (stdout and stderr) for cmd scripts from powershell?

Tags:

powershell

cmd

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

Colored output of build script from cmd

When I run same commands in PS it outputs everything in red (probably because it's for err output).

Red output of powershell

Can I keep colors somehow?

like image 919
xvorsx Avatar asked Sep 17 '13 23:09

xvorsx


2 Answers

At first, I didn't think it was possible.

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

You should be able to use the PowerShell script from there to create what you need.

like image 158
aphoria Avatar answered Oct 10 '22 23:10

aphoria


I'm not positive this will work, but if you don't mind redirecting stderr to stdout, PowerShell won't try to color everything red. To do this, just add 2>&1 when you run your cmd script, e.g.

build.cmd 2>&1
like image 34
Jason Shirk Avatar answered Oct 11 '22 00:10

Jason Shirk