Change the color of text output in windows for stderr

I recently found a post that gave a solution to output stderr text of a different color for Linux (bash)

They created the following bash script script

#!/bin/bash
{ $* 2>&1>&3|sed 's,.*,\x1B[33m&\x1B[0m,'>&2;} 3>&1

this causes yellow text to be output when it is from stderr. stdout still prints the same color.

The script was saved in a directory on $ PATH called color. This allows me to run the script using make or scons, and it will hi-lite all the text from stderr in yellow. (can make the text red by changing 33 m to 31 m)

color make CPU=x64 

This is very useful for finding compilation errors.

Is there a similar script that can be used for Windows cmd shell?

Note. I have sed installed on my windows computer if this is useful.

+5
3

escape- ANSI Windows 'cmd.exe, . ansicon. cmd.exe color.bat :

@Echo Off
(((%* 1>&3) 2>&1) | "c:\Program Files (x86)\GnuWin32\bin\sed.exe" "s,.*,\x1B[33m&\x1B[0m," 1>&2) 3>&1

, ( stdout stderr ). , sed.exe, .

, cygwin. color.sh script, .bat , , . , , :

./color.sh cmd /c test.bat
+6

Batch, .. Ansi, no sed.exe .., findstr:

any_command 2>&1 1>&3 | findstr /N /A:4E "^"

stderr, , findstr, , . .exe, stderr .

+3

@MBu, @ gnash117

I renamed colorto co, because it coloris a Windows command, and I expanded it:

:: color output - Displays stderr output in different color
::
:: Credits to MBu and gnash117 at http://stackoverflow.com/questions/10095886/change-text-output-color-on-windows-for-stderr#10118710
:: 
:: Requires:
::   - http://sourceforge.net/projects/mingw/files/MSYS/
::   - http://adoxa.altervista.org/ansicon/
::   - http://www.autohotkey.com/
::
@echo off

if "%1"=="" goto :Help

:: 1;31 ... intense red foreground (see https://github.com/adoxa/ansicon/blob/master/sequences.txt for more colors)
:: \x07 ... BEL, but doesn't work :-(
(((%* 1>&3) 2>&1) | sed "s/.*/\x07\x1B[1;31m&\x1B[0m/" 1>&2) 3>&1
goto :EOF

:Help
setlocal
::------------------------------------------------
:: Adapt these in pairs according to your likings
set invokeKeys=[Shift]+[Enter]
set invokeHotkeys=+Enter
set invokeAfterRemoveKeys=[Alt]+[Enter]
set invokeAfterRemoveHotkeys=!Enter
set removeKeys=[Alt]+[c]
set removeHotkeys=!c
::-----------------------------------------------
set invokeText=invokes the entered command after preceding it with '%0 '
set invokeAfterRemoveText=invokes the entered command after removing the first three characters from the beginning
set removeText=removes the first three characters from the command line
echo Colors a command stderr output as defined in %~f0
echo Usage:
echo   - Preceed a command with '%0 ' (e.g.: 'co dir not.existing.file' will show the resulting error message in a different color)
echo   - If the AutoHotkey script below is active:
echo     - %invokeKeys% ... %invokeText%
echo     - %invokeAfterRemoveKeys% ... %invokeAfterRemoveText%
echo     - %removeKeys% ... %removeText%
echo(
echo       The latter two are useful when using the command line history and having used %invokeKeys% before.
echo(
echo     Enabled by AutoHotkey script:
echo(
echo       #IfWinActive ahk_class ConsoleWindowClass
echo       ; %invokeText%
echo       %invokeHotkeys%::Send {Home}%0 {Enter}
echo       ; %invokeAfterRemoveText%
echo       %invokeAfterRemoveHotkeys%::SendInput {Home}{Del 3}{Enter}
echo       ; %removeText%
echo       %removeHotkeys%::SendInput {Home}{Del 3}{End}
echo       #IfWinActive
endlocal
:EOF
+2
source

All Articles