How to change the colour the cmd to set it to specific lines [duplicate] - batch-file

I know that the color bf command sets the colors of the whole command line window but I wanted to to print one single line in a different color.

I wanted to to print one single line in a different color.
Use ANSI Escape Sequences.
Windows before 10 - no native support for ANSI colors on the console
For Windows version below 10, the Windows command console doesn't support output coloring by default. You could install either Cmder, ConEmu, ANSICON or Mintty (used by default in GitBash and Cygwin) to add coloring support to your Windows command console.
Windows 10 - Command Line Colors
Starting from Windows 10 the Windows console support ANSI Escape Sequences and some colors by default. The feature shipped with the Threshold 2 Update in Nov 2015.
MSDN Documentation
Update (05-2019): The ColorTool enables you to change the color scheme of the console. It's part of the Microsoft Terminal project.
Demo
Batch Command
The win10colors.cmd was written by Michele Locati:
The text below is stripped of special characters and will not work. You must copy it from here.
#echo off
cls
echo [101;93m STYLES [0m
echo ^<ESC^>[0m [0mReset[0m
echo ^<ESC^>[1m [1mBold[0m
echo ^<ESC^>[4m [4mUnderline[0m
echo ^<ESC^>[7m [7mInverse[0m
echo.
echo [101;93m NORMAL FOREGROUND COLORS [0m
echo ^<ESC^>[30m [30mBlack[0m (black)
echo ^<ESC^>[31m [31mRed[0m
echo ^<ESC^>[32m [32mGreen[0m
echo ^<ESC^>[33m [33mYellow[0m
echo ^<ESC^>[34m [34mBlue[0m
echo ^<ESC^>[35m [35mMagenta[0m
echo ^<ESC^>[36m [36mCyan[0m
echo ^<ESC^>[37m [37mWhite[0m
echo.
echo [101;93m NORMAL BACKGROUND COLORS [0m
echo ^<ESC^>[40m [40mBlack[0m
echo ^<ESC^>[41m [41mRed[0m
echo ^<ESC^>[42m [42mGreen[0m
echo ^<ESC^>[43m [43mYellow[0m
echo ^<ESC^>[44m [44mBlue[0m
echo ^<ESC^>[45m [45mMagenta[0m
echo ^<ESC^>[46m [46mCyan[0m
echo ^<ESC^>[47m [47mWhite[0m (white)
echo.
echo [101;93m STRONG FOREGROUND COLORS [0m
echo ^<ESC^>[90m [90mWhite[0m
echo ^<ESC^>[91m [91mRed[0m
echo ^<ESC^>[92m [92mGreen[0m
echo ^<ESC^>[93m [93mYellow[0m
echo ^<ESC^>[94m [94mBlue[0m
echo ^<ESC^>[95m [95mMagenta[0m
echo ^<ESC^>[96m [96mCyan[0m
echo ^<ESC^>[97m [97mWhite[0m
echo.
echo [101;93m STRONG BACKGROUND COLORS [0m
echo ^<ESC^>[100m [100mBlack[0m
echo ^<ESC^>[101m [101mRed[0m
echo ^<ESC^>[102m [102mGreen[0m
echo ^<ESC^>[103m [103mYellow[0m
echo ^<ESC^>[104m [104mBlue[0m
echo ^<ESC^>[105m [105mMagenta[0m
echo ^<ESC^>[106m [106mCyan[0m
echo ^<ESC^>[107m [107mWhite[0m
echo.
echo [101;93m COMBINATIONS [0m
echo ^<ESC^>[31m [31mred foreground color[0m
echo ^<ESC^>[7m [7minverse foreground ^<-^> background[0m
echo ^<ESC^>[7;31m [7;31minverse red foreground color[0m
echo ^<ESC^>[7m and nested ^<ESC^>[31m [7mbefore [31mnested[0m
echo ^<ESC^>[31m and nested ^<ESC^>[7m [31mbefore [7mnested[0m

This isn't a great answer, but if you know the target workstation has Powershell you can do something like this (assuming BAT / CMD script):
CALL:ECHORED "Print me in red!"
:ECHORED
%Windir%\System32\WindowsPowerShell\v1.0\Powershell.exe write-host -foregroundcolor Red %1
goto:eof
Edit: (now simpler!)
It's an old answer but I figured I'd clarify & simplify a bit
PowerShell is now included in all versions of Windows since 7. Therefore the syntax for this answer can be shortened to a simpler form:
the path doesn't need to be specified since it should be in the environment variable already.
unambiguous commands can be abbreviated. For example you can:
use -fore instead of -foregroundcolor
use -back instead of -backgroundcolor
the command can also basically be used 'inline' in place of echo
(rather than creating a separate batch file as above).
Example:
powershell write-host -fore Cyan This is Cyan text
powershell write-host -back Red This is Red background
More Information:
The complete list of colors and more information is available in the
- PowerShell Documentation for Write-Host

This is a self-compiled bat/.net hybrid (should be saved as .BAT) that can be used on any system that have installed .net framework (it's a rare thing to see an windows without .NET framework even for the oldest XP/2003 installations) . It uses jscript.net compiler to create an exe capable to print strings with different background/foreground color only for the current line.
#if (#X)==(#Y) #end /* JScript comment
#echo off
setlocal
for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%SystemRoot%\Microsoft.NET\Framework\*jsc.exe"') do (
set "jsc=%%v"
)
if not exist "%~n0.exe" (
"%jsc%" /nologo /out:"%~n0.exe" "%~dpsfnx0"
)
%~n0.exe %*
endlocal & exit /b %errorlevel%
*/
import System;
var arguments:String[] = Environment.GetCommandLineArgs();
var newLine = false;
var output = "";
var foregroundColor = Console.ForegroundColor;
var backgroundColor = Console.BackgroundColor;
var evaluate = false;
var currentBackground=Console.BackgroundColor;
var currentForeground=Console.ForegroundColor;
//http://stackoverflow.com/a/24294348/388389
var jsEscapes = {
'n': '\n',
'r': '\r',
't': '\t',
'f': '\f',
'v': '\v',
'b': '\b'
};
function decodeJsEscape(_, hex0, hex1, octal, other) {
var hex = hex0 || hex1;
if (hex) { return String.fromCharCode(parseInt(hex, 16)); }
if (octal) { return String.fromCharCode(parseInt(octal, 8)); }
return jsEscapes[other] || other;
}
function decodeJsString(s) {
return s.replace(
// Matches an escape sequence with UTF-16 in group 1, single byte hex in group 2,
// octal in group 3, and arbitrary other single-character escapes in group 4.
/\\(?:u([0-9A-Fa-f]{4})|x([0-9A-Fa-f]{2})|([0-3][0-7]{0,2}|[4-7][0-7]?)|(.))/g,
decodeJsEscape);
}
function printHelp( ) {
print( arguments[0] + " -s string [-f foreground] [-b background] [-n] [-e]" );
print( " " );
print( " string String to be printed" );
print( " foreground Foreground color - a " );
print( " number between 0 and 15." );
print( " background Background color - a " );
print( " number between 0 and 15." );
print( " -n Indicates if a new line should" );
print( " be written at the end of the ");
print( " string(by default - no)." );
print( " -e Evaluates special character " );
print( " sequences like \\n\\b\\r and etc ");
print( "" );
print( "Colors :" );
for ( var c = 0 ; c < 16 ; c++ ) {
Console.BackgroundColor = c;
Console.Write( " " );
Console.BackgroundColor=currentBackground;
Console.Write( "-"+c );
Console.WriteLine( "" );
}
Console.BackgroundColor=currentBackground;
}
function errorChecker( e:Error ) {
if ( e.message == "Input string was not in a correct format." ) {
print( "the color parameters should be numbers between 0 and 15" );
Environment.Exit( 1 );
} else if (e.message == "Index was outside the bounds of the array.") {
print( "invalid arguments" );
Environment.Exit( 2 );
} else {
print ( "Error Message: " + e.message );
print ( "Error Code: " + ( e.number & 0xFFFF ) );
print ( "Error Name: " + e.name );
Environment.Exit( 666 );
}
}
function numberChecker( i:Int32 ){
if( i > 15 || i < 0 ) {
print("the color parameters should be numbers between 0 and 15");
Environment.Exit(1);
}
}
if ( arguments.length == 1 || arguments[1].toLowerCase() == "-help" || arguments[1].toLowerCase() == "-help" ) {
printHelp();
Environment.Exit(0);
}
for (var arg = 1; arg <= arguments.length-1; arg++ ) {
if ( arguments[arg].toLowerCase() == "-n" ) {
newLine=true;
}
if ( arguments[arg].toLowerCase() == "-e" ) {
evaluate=true;
}
if ( arguments[arg].toLowerCase() == "-s" ) {
output=arguments[arg+1];
}
if ( arguments[arg].toLowerCase() == "-b" ) {
try {
backgroundColor=Int32.Parse( arguments[arg+1] );
} catch(e) {
errorChecker(e);
}
}
if ( arguments[arg].toLowerCase() == "-f" ) {
try {
foregroundColor=Int32.Parse(arguments[arg+1]);
} catch(e) {
errorChecker(e);
}
}
}
Console.BackgroundColor = backgroundColor ;
Console.ForegroundColor = foregroundColor ;
if ( evaluate ) {
output=decodeJsString(output);
}
if ( newLine ) {
Console.WriteLine(output);
} else {
Console.Write(output);
}
Console.BackgroundColor = currentBackground;
Console.ForegroundColor = currentForeground;
Here's the help message:
Example:
coloroutput.bat -s "aa\nbb\n\u0025cc" -b 10 -f 3 -n -e
You can also find this script here.
You can also check carlos' color function -> http://www.dostips.com/forum/viewtopic.php?f=3&t=4453

Windows 10 - TH2 and above:
(a.k.a. Version 1511, build 10586, release 2015-11-10)
At Command Prompt:
echo ^[[32m HI ^[[0m
Using the actual keys:   echo Ctrl+[[32m HI Ctrl+[[0mEnter
You should see a green "HI" below it.
Code numbers can be found here:
https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
Notepad:
To save this into notepad, you can type ESC into it using: Alt+027 with the numpad, then the [32m part. Another trick when I was on a laptop, redirect the line above into a file to get started, then cut and paste:
echo echo ^[[32m HI ^[[0m >> batch_file.cmd

You can just creates files with the name of the word to print, uses findstr which can print in color, and then erases the file. Try this example:
#echo off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
call :ColorText 0a "green"
call :ColorText 0C "red"
call :ColorText 0b "cyan"
echo(
call :ColorText 19 "blue"
call :ColorText 2F "white"
call :ColorText 4e "yellow"
goto :eof
:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
Run color /? to get a list of colors.

You could use ANSICON to enable ANSI terminal codes in older versions of Windows. There are 32 and 64 bit versions that I have used in Windows XP and Windows 7.

I was annoyed by the lack of proper coloring in cmd too, so I went ahead and created cmdcolor. It's just an stdout proxy, which looks for a limited set of ANSI/VT100 control sequences (in other words, like in bash), i.e. echo \033[31m RED \033[0m DEFAULT | cmdcolor.exe.
Usage and downloads.

I looked at this because I wanted to introduce some simple text colors to a Win7 Batch file. This is what I came up with. Thanks for your help.
#echo off
cls && color 08
rem .... the following line creates a [DEL] [ASCII 8] [Backspace] character to use later
rem .... All this to remove [:]
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (set "DEL=%%a")
echo.
<nul set /p="("
call :PainText 09 "BLUE is cold" && <nul set /p=") ("
call :PainText 02 "GREEN is earth" && <nul set /p=") ("
call :PainText F0 "BLACK is night" && <nul set /p=")"
echo.
<nul set /p="("
call :PainText 04 "RED is blood" && <nul set /p=") ("
call :PainText 0e "YELLOW is pee" && <nul set /p=") ("
call :PainText 0F "WHITE all colors"&& <nul set /p=")"
goto :end
:PainText
<nul set /p "=%DEL%" > "%~2"
findstr /v /a:%1 /R "+" "%~2" nul
del "%~2" > nul
goto :eof
:end
echo.
pause

There is an accepted answer with more than 250 upvotes already. The reason I am still contributing is that the escape character required for echoing is not accepted by many editors (I am using, e.g., MS Code) and all other solutions require some third-party (non-Windows-default) pieces of software.
The work-around with using only plain batch commands is using PROMPT instead of ECHO. The PROMPT command accepts the escape character in an any-editor-friendly way as a $Echaracter sequence. (Simply replace the Esc in the ASCII Escape codes) with $E.
Here is a demo code:
#ECHO OFF
:: Do not pollute environment with the %prompt.bak% variable
:: ! forgetting ENDLOCAL at the end of the batch leads to prompt corruption
SETLOCAL
:: Old prompt settings backup
SET prompt.bak=%PROMPT%
:: Entering the "ECHO"-like section
:: Forcing prompt to display after every command (see below)
ECHO ON
:: Setting the prompt using the ANSI Escape sequence(s)
:: - Always start with $E[1A, otherwise the text would appear on a next line
:: - Then the decorated text follows
:: - And it all ends with $E30;40m, which makes the following command invisible
:: - assuming default background color of the screen
# PROMPT $E[1A$E[30;42mHELLO$E[30;40m
:: An "empty" command that forces the prompt to display.
:: The word "rem" is displayed along with the prompt text but is made invisible
rem
:: Just another text to display
# PROMPT $E[1A$E[33;41mWORLD$E[30;40m
rem
:: Leaving the "ECHO"-like section
#ECHO OFF
:: Or a more readable version utilizing the cursor manipulation ASCII ESC sequences
:: the initial sequence
PROMPT $E[1A
:: formating commands
PROMPT %PROMPT%$E[32;44m
:: the text
PROMPT %PROMPT%This is an "ECHO"ed text...
:: new line; 2000 is to move to the left "a lot"
PROMPT %PROMPT%$E[1B$E[2000D
:: formating commands fro the next line
PROMPT %PROMPT%$E[33;47m
:: the text (new line)
PROMPT %PROMPT%...spreading over two lines
:: the closing sequence
PROMPT %PROMPT%$E[30;40m
:: Looks like this without the intermediate comments:
:: PROMPT $E[1A
:: PROMPT %PROMPT%$E[32;44m
:: PROMPT %PROMPT%This is an "ECHO"ed text...
:: PROMPT %PROMPT%$E[1B$E[2000D
:: PROMPT %PROMPT%$E[33;47m
:: PROMPT %PROMPT%...spreading over two lines
:: PROMPT %PROMPT%$E[30;40m
:: show it all at once!
ECHO ON
rem
#ECHO OFF
:: End of "ECHO"-ing
:: Setting prompt back to its original value
:: - We prepend the settings with $E[37;40m in case
:: the original prompt settings do not specify color
:: (as they don't by default).
:: - If they do, the $E[37;40m will become overridden, anyway.
:: ! It is important to write this command
:: as it is with `ENDLOCAL` and in the `&` form.
ENDLOCAL & PROMPT $E[37;40m%prompt.bak%
EXIT /B 0
NOTE: The only drawback is that this technique collides with user cmd color settings (color command or settings) if not known explicitly.
-- Hope this helps as thi is the only solution acceptable for me for the reasons mentioned at the beginning. --
EDIT:
Based on comments, I am enclosing another snippet inspired by #Jeb. It:
Shows how to obtain and use the "Esc" character runtime (rather than entering it to an editor) (Jeb's solution)
Uses "native" ECHO command(s)
So it does not affect local PROMPT value
Demonstrates that coloring the ECHO output inevitably affect PROMPT color so the color must be reset, anyway
#ECHO OFF
:: ! To observe color effects on prompt below in this script
:: run the script from a fresh cmd window with no custom
:: prompt settings
:: Only not to pollute the environment with the %\e% variable (see below)
:: Not needed because of the `PROMPT` variable
SETLOCAL
:: Parsing the `escape` character (ASCII 27) to a %\e% variable
:: Use %\e% in place of `Esc` in the [http://ascii-table.com/ansi-escape-sequences.php]
FOR /F "delims=#" %%E IN ('"prompt #$E# & FOR %%E IN (1) DO rem"') DO SET "\e=%%E"
:: Demonstrate that prompt did not get corrupted by the previous FOR
ECHO ON
rem : After for
#ECHO OFF
:: Some fancy ASCII ESC staff
ECHO [ ]
FOR /L %%G IN (1,1,10) DO (
TIMEOUT /T 1 > NUL
ECHO %\e%[1A%\e%[%%GC%\e%[31;43m.
ECHO %\e%[1A%\e%[11C%\e%[37;40m]
)
:: ECHO another decorated text
:: - notice the `%\e%[30C` cursor positioning sequence
:: for the sake of the "After ECHO" test below
ECHO %\e%[1A%\e%[13C%\e%[32;47mHELLO WORLD%\e%[30C
:: Demonstrate that prompt did not get corrupted by ECHOing
:: neither does the cursor positioning take effect.
:: ! But the color settings do.
ECHO ON
rem : After ECHO
#ECHO OFF
ENDLOCAL
:: Demonstrate that color settings do not reset
:: even when out of the SETLOCAL scope
ECHO ON
rem : After ENDLOCAL
#ECHO OFF
:: Reset the `PROMPT` color
:: - `PROMPT` itself is untouched so we did not need to backup it.
:: - Still ECHOING in color apparently collide with user color cmd settings (if any).
:: ! Resetting `PROMPT` color this way extends the `PROMPT`
:: by the initial `$E[37;40m` sequence every time the script runs.
:: - Better solution then would be to end every (or last) `ECHO` command
:: with the `%\e%[37;40m` sequence and avoid setting `PROMPT` altogether.
:: which makes this technique preferable to the previous one (before EDIT)
:: - I am keeping it this way only to be able to
:: demonstrate the `ECHO` color effects on the `PROMPT` above.
PROMPT $E[37;40m%PROMPT%
ECHO ON
rem : After PROMPT color reset
#ECHO OFF
EXIT /B 0

I'm adding an answer to address an issue noted in some comments above: that inline ansi color codes can misbehave when inside a FOR loop (actually, within any parenthesized block of code). The .bat code below demonstrates (1) the use of inline color codes, (2) the color failure that can occur when inline color codes are used in a FOR loop or within a parenthesized block of code, and (3) a solution to the problem. When the .bat code executes, tests 2 and 3 demonstrate the colorcode failure, and test 4 shows no failure because it implements the solution.
[EDIT 2020-04-07: I found another solution that's presumably more efficient than calling a subroutine. Enclose the FINDSTR phrase in parentheses, as in the following line:
echo success | (findstr /R success)
ENDEDIT]
Note: In my (limited) experience, the color code problem manifests only after input is piped to FINDSTR inside the block of code. That's how the following .bat reproduces the problem. It's possible the color code problem is more general than after piping to FINDSTR. If someone can explain the nature of the problem, and if there's a better way to solve it, I'd appreciate it.
#goto :main
:resetANSI
EXIT /B
rem The resetANSI subroutine is used to fix the colorcode
rem bug, even though it appears to do nothing.
:main
#echo off
setlocal EnableDelayedExpansion
rem Define some useful colorcode vars:
for /F "delims=#" %%E in ('"prompt #$E# & for %%E in (1) do rem"') do set "ESCchar=%%E"
set "green=%ESCchar%[92m"
set "yellow=%ESCchar%[93m"
set "magenta=%ESCchar%[95m"
set "cyan=%ESCchar%[96m"
set "white=%ESCchar%[97m"
set "black=%ESCchar%[30m"
echo %white%Test 1 is NOT in a FOR loop nor within parentheses, and color works right.
echo %yellow%[Test 1] %green%This is Green, %magenta%this is Magenta, and %yellow%this is Yellow.
echo %Next, the string 'success' will be piped to FINDSTR...
echo success | findstr /R success
echo %magenta%This is magenta and FINDSTR found and displayed 'success'.%yellow%
echo %green%This is green.
echo %cyan%Test 1 completed.
echo %white%Test 2 is within parentheses, and color stops working after the pipe to FINDSTR.
( echo %yellow%[Test 2] %green%This is Green, %magenta%this is Magenta, and %yellow%this is Yellow.
echo %Next, the string 'success' will be piped to FINDSTR...
echo success | findstr /R success
echo %magenta%This is supposed to be magenta and FINDSTR found and displayed 'success'.
echo %green%This is supposed to be green.
)
echo %cyan%Test 2 completed.
echo %white%Test 3 is within a FOR loop, and color stops working after the pipe to FINDSTR.
for /L %%G in (3,1,3) do (
echo %yellow%[Test %%G] %green%This is Green, %magenta%this is Magenta, and %yellow%this is Yellow.
echo %Next, the string 'success' will be piped to FINDSTR...
echo success | findstr /R success
echo %magenta%This is supposed to be magenta and FINDSTR found and displayed 'success'.
echo %green%This is supposed to be green.
)
echo %cyan%Test 3 completed.
echo %white%Test 4 is in a FOR loop but color works right because subroutine :resetANSI is
echo called after the pipe to FINDSTR, before the next color code is used.
for /L %%G in (4,1,4) do (
echo %yellow%[Test %%G] %green%This is Green, %magenta%this is Magenta, and %yellow%this is Yellow.
echo %Next, the string 'success' will be piped to FINDSTR...
echo success | findstr /R success
call :resetANSI
echo %magenta%This is magenta and FINDSTR found and displayed 'success'.
echo %green%This is green.
)
echo %cyan%Test 4 completed.%white%
EXIT /B

An option for non windows 10 users that doesn't require calling labels, avoiding the delays that go with doing so.
Below is a macro verison of a findstr colorprint routine
usage - where BF is replaced with the hex digit values of the background / Foreground colors:
%Col%{BF}{"string to print"}
#Echo off & CD "%TEMP%"
For /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (set "DEL=%%a")
Set "Col=For %%l in (1 2)Do if %%l==2 (Set "_Str="&(For /F "tokens=1,2 Delims={}" %%G in ("!oline!")Do Set "C_Out=%%G" & Set "_Str=%%~H")&(For %%s in (!_Str!)Do Set ".Str=%%s")&( <nul set /p ".=%DEL%" > "!_Str!" )&( findstr /v /a:!C_Out! /R "^$" "!_Str!" nul )&( del " !_Str!" > nul 2>&1 ))Else Set Oline="
Setlocal EnableDelayedExpansion
rem /* concatenation of multiple macro expansions requires the macro to be expanded within it's own code block. */
(%Col%{02}{"green on black,"}) & (%Col%{10}{black on blue})
Echo/& (%Col%{04}{red on black}) & (%Col%{34}{" red on blue"})
Goto :Eof
A more robust version of the macro replete with error handling.
#Echo off & PUSHD "%TEMP%"
rem /* Macro Definitions */
(Set \n=^^^
%= macro newline Do not modify =%
)
(Set LF=^
%= linefeed. Do not modify =%)
If "!![" == "[" (
Echo/%%COL%% macro must be defined prior to delayed expansion being enabled
Goto :end
)
For /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (set "DEL=%%a")
rem /* %hCol% - Alternate color macro; escaped for use in COL macro. No error checking. Usage: (%hCol:?=HEXVALUE%Output String) */
Set "hCol=For %%o in (1 2)Do if %%o==2 (^<nul set /p ".=%DEL%" ^> "!os!" ^& findstr /v /a:? /R "^$" "!os!" nul ^& del "!os!" ^> nul 2^>^&1 )Else Set os="
rem /* %TB% - used with substitution within COL macro to format help output; not fit for general use, */
Set "TB=^&^< nul Set /P "=.%DEL%!TAB!"^&"
rem /* %COL% - main color output macro. Usage: (%COL%{[a-f0-9][a-f0-9]}{String to Print}) */
Set COL=Set "_v=1"^&Set "Oline="^& For %%l in (1 2)Do if %%l==2 (%\n%
If not "!Oline!" == "" (%\n%
Set "_Str="%\n%
For /F "tokens=1,2 Delims={}" %%G in ("!oline!")Do (%\n%
Set "Hex=%%G"%\n%
Set "_Str=%%~H"%\n%
)%\n%
Echo/!Hex!^|findstr /RX "[0-9a-fA-F][0-9a-fA-F]" ^> nul ^|^| (Echo/^&(%hCol:?=04%Invalid - )%TB%(%hCol:?=06%Bad Hex value.)%TB%(%hCol:?=01%%%COL%%{!Hex!}{!_Str!})%TB:TAB=LF%(%hCol:?=02%!Usage!)^&Set "_Str="^&Set "_v=0")%\n%
If not "!_Str!" == "" (%\n%
^<nul set /p ".=%DEL%" ^> "!_Str!"%\n%
findstr /v /a:!Hex! /R "^$" "!_Str!" nul %\n%
del "!_Str!" ^> nul 2^>^&1%\n%
)Else If not !_v! EQU 0 (%\n%
Echo/^&(%hCol:?=04%Invalid -)%TB%(%hCol:?=06%Arg 2 absent.)%TB%(%hCol:?=01%%%COL%%!Oline!)%TB:TAB=LF%(%hCol:?=04%Input is required for output string.)%TB:TAB=LF%(%hCol:?=02%!Usage!)%\n%
)%\n%
)Else (Echo/^&(%hCol:?=04%Invalid -)%TB%(%hCol:?=06%No Args)%TB:TAB=!TAB!!TAB!%(%hCol:?=01%%%COL%%!Oline!)%TB:TAB=LF%(%hCol:?=02%!Usage!))%\n%
)Else Set Oline=
Set "usage=%%COL%%{[a-f0-9][a-f0-9]}{String to Print}"
For /F eol^=^%LF%%LF%^ delims^= %%A in ('forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(0x09"') do Set "TAB=%%A"
rem /* removes escaping from macros to enable use outside of COL macro */
Set "hCol=%hCol:^=%"
Set "TB=%TB:^=%"
Setlocal EnableDelayedExpansion
rem /* usage examples */
(%COL%{02}{"green on black,"}) & (%COL%{10}{"black on blue"})
Echo/
(%COL%{04}{"red on black"}) & (%COL%{34}{" red on blue"})&(%COL%{40}{"black on red"})
Echo/& %COL%{03}{Demonstration of error handling-}
rem /* error handling */
Echo/%TB:TAB=!LF! % %hCol:?=20%Example 1 - No args
%COL%
Echo/%TB:TAB=!LF! % %hCol:?=20%Example 2 - Missing 2nd Arg
%COL%{ff}
Echo/%TB:TAB=!LF! % %hCol:?=20%Example 3 - Invalid hex value for 1st Arg
%COL%{HF}{string}
Echo/%TB:TAB=!LF! % %hCol:?=0d%Done
:end
POPD
Goto :Eof

you could use cecho.. you can also use it to embed right into your script so you dont have to carry along a .com or .exe
http://www.codeproject.com/Articles/17033/Add-Colors-to-Batch-Files

The following code consists of two parts. If it is convenient for you too, there is also a .txt format in this .cmd file, below the "double" line (====).
::adonios77
::This is a .cmd file
#ECHO OFF
TITLE Colored Command Prompt echoes HELP
mode con: cols=55 lines=47
CLS
COLOR 0f
echo [93m
ECHO This is just help, as optical example,
ECHO when make or modify colorful command prompt echoes.
ECHO.
ECHO More info in Source:
ECHO [4m[94mhttps://stackoverflow.com/questions/2048509/how-to-echo-with-different-colors-in-the-windows-command-line[0m
ECHO.
ECHO [0mESC[0m "Text" Default colours Text[0m
ECHO [7mESC[7m "Text" Inversed Back-Fore colors[0m
ECHO [101mESC[101m "Text" in Red Background[0m
ECHO [91mESC[91m "Text" in Red Foreground)[0m
echo.
echo To make an ESC special character, (ASCII Escape code)
echo open or edit a .txt or .bat or .cmd file,
echo (hold)L-Alt and (type)027 in NumPad)
echo Or, in Command Prompt, (can't copy/paste special char.)
echo just press Ctrl+[
echo (it should look like: "echo ^[[33m'Text'^[[0m")
echo.
echo STYLES
echo [0mESC[0m Reset[0m
echo [1mESC[1m Bold [90m*This is not work for me[0m
echo [4mESC[4m Underline[0m
echo [7mESC[7m[0m Inverse
echo.
echo COLORS# Foreground-Background (color /? HEX) && echo.
echo [90mDark[0m / [100mLight[0m
echo Fore-Back / Fore-Back
echo Black * [100m[30m30[0m-[4m[40m40 [0m (0) / (8) [90m90[0m-[100m100 [0m
echo Red [31m31[0m-[41m41 [0m (4) / (C) [91m91[0m-[101m101 [0m
echo Green [32m32[0m-[42m42 [0m (2) / (A) [92m92[0m-[102m102 [0m
echo Yellow [33m33[0m-[90m[43m43 [0m (6) / (E) [93m93[0m-[90m[103m103 [0m
echo Blue [34m34[0m-[44m44 [0m (1) / (9) [94m94[0m-[104m104 [0m
echo Magenta [35m35[0m-[45m45 [0m (5) / (D) [95m95[0m-[105m105 [0m
echo Cyan [36m36[0m-[46m46 [0m (3) / (B) [96m96[0m-[106m106 [0m
echo White * [37m37[0m-[47m47 [0m (7) / (F) [97m97[0m-[7;97m107 [0m
echo.
echo Note: use ESC[0m at the end of (every) line.
echo.
echo COMBINATIONS
echo [7;91mESC[7;91m inverse red foreground color ESC[0m[0m
echo.
ECHO. && PAUSE
exit
============================================================
:: This is a .txt file.
This is just help, as optical example,
when make or modify colorful command prompt echoes.
More info in Source:
https://stackoverflow.com/questions/2048509/how-to-echo-with-different-colors-in-the-windows-command-line
To make an ESC special character, (),
open or edit a .txt or .bat or .cmd file,
(hold)L-Alt and (type)027 in NumPad)
STYLES
[0m Reset
[1m Bold
[4m Underline
[7m Inverse
COLORS# (Foreground-Background)
Dark / Light
Fore-Back / Fore-Back
Black 30-40 (0) / (8) 90-100
Red 31-41 (4) / (C) 91-101
Green 32-42 (2) / (A) 92-102
Yellow 33-43 (6) / (E) 93-103
Blue 34-44 (1) / (9) 94-104
Magenta 35-45 (5) / (D) 95-105
Cyan 36-46 (3) / (B) 96-106
White 37-47 (7) / (F) 97-107
COMBINATIONS
ESC[7;31m inverse red foreground color 0m
Note: use ESC[0m at the end of (every) line.
examples:
#ECHO OFF
ECHO Default Text
ECHO [7m"Text" Inversed Back-Fore colors (7m)[0m
ECHO [101m"Text" in Red Background (101m)[0m
ECHO [91m"Text" in Red Foreground (91m)[0m
============================================================
Also, I figured out that with this way can be change the way the Command Prompt looks like, temporarily or permanently.
The following TEXT code is an example of:
This is a .txt file.
Antony's examples:
prompt $Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$S $T$_ $P\$_$G
gives something like that:
==================== 19:53:02,73
C:\Windows\system32\
>
For All Users & Permanent:
(if there is space between characters, must double quoted [""])
SETX PROMPT /M $Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$S$S$T$_$_$S$P\$_$G$S
gives something like that:
==================== 9:01:23,17
C:\Windows\system32\
>
NOTE: Variables created or modified by SETX
will be available at the next logon session.
Now let's give colors to the above examples. The result in the image above.
COLORED PROMPT examples:
For only the current User:
prompt $E[91m$E[40m$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$S $T$E[93m$_ $P\$_$G$E[0m
or
For All Users and Permanently:
SETX PROMPT /M $E[91m$E[40m$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$Q$S$S$T$E[93m$_$_$S$P\$_$G$S$E[0m

Solution for changing the foreground and background colors and writing without new lines.
It does not create any temporary files.
No special editors are required, so Notepad can be used for editing.
The first parameter for the :color subroutine is the color code, the rest of the (optional) parameters are the text to display. If the last parameter is $ then a new line is written at the end.
The color codes are the same as for the color command.
The :echo subroutine can be used to display a text without new line (unlike regular echo).
#echo off
call :color 4
call :echo Red foreground
call :color 7 " and "
call :color 4f
echo Red background
call :color
echo Back to normal
call :color 70 "Black "
call :color 1 "Blue "
call :color 2 "Green "
call :color 3 "Aqua "
call :color 4 "Red "
call :color 5 "Purple "
call :color 6 "Yellow "
call :color 7 "White "
call :color 8 "Gray "
call :color 9 "LightBlue" $
call :color a "LightGreen "
call :color b "LightAqua "
call :color c "LightRed "
call :color d "LightPurple "
call :color e "LightYellow "
call :color f "BrightWhite " $
call :color 1f Blue back
call :color 2f Green back
call :color 3f Aqua back
call :color 4f Red back
call :color 5f Purple back
call :color 6f Yellow back
call :color 7f White back
call :color 8f Gray back
call :color 9f "LightBlue back" $
call :color a0 LightGreen back
call :color b0 LightAqua back
call :color c0 LightRed back
call :color d0 LightPurple back
call :color e0 LightYellow back
call :color f0 LightWhite back $
call :color
echo %ESC%[4mUnderline%ESC%[0m.
pause
goto :eof
:: Displays a text without new line at the end (unlike echo)
:echo
#<nul set /p ="%*"
#goto :eof
:: Change color to the first parameter (same codes as for the color command)
:: And display the other parameters (write $ at the end for new line)
:color
#echo off
IF [%ESC%] == [] for /F %%a in ('echo prompt $E ^| cmd') do set "ESC=%%a"
SET color=0%1
IF [%color%] == [0] SET color=07
SET fore=%color:~-1%
SET back=%color:~-2,1%
SET color=%ESC%[
if %fore% LEQ 7 (
if %fore% == 0 SET color=%ESC%[30
if %fore% == 1 SET color=%ESC%[34
if %fore% == 2 SET color=%ESC%[32
if %fore% == 3 SET color=%ESC%[36
if %fore% == 4 SET color=%ESC%[31
if %fore% == 5 SET color=%ESC%[35
if %fore% == 6 SET color=%ESC%[33
if %fore% == 7 SET color=%ESC%[37
) ELSE (
if %fore% == 8 SET color=%ESC%[90
if %fore% == 9 SET color=%ESC%[94
if /i %fore% == a SET color=%ESC%[92
if /i %fore% == b SET color=%ESC%[96
if /i %fore% == c SET color=%ESC%[91
if /i %fore% == d SET color=%ESC%[95
if /i %fore% == e SET color=%ESC%[93
if /i %fore% == f SET color=%ESC%[97
)
if %back% == 0 (SET color=%color%;40) ELSE (
if %back% == 1 SET color=%color%;44
if %back% == 2 SET color=%color%;42
if %back% == 3 SET color=%color%;46
if %back% == 4 SET color=%color%;41
if %back% == 5 SET color=%color%;45
if %back% == 6 SET color=%color%;43
if %back% == 7 SET color=%color%;47
if %back% == 8 SET color=%color%;100
if %back% == 9 SET color=%color%;104
if /i %back% == a SET color=%color%;102
if /i %back% == b SET color=%color%;106
if /i %back% == c SET color=%color%;101
if /i %back% == d SET color=%color%;105
if /i %back% == e SET color=%color%;103
if /i %back% == f SET color=%color%;107
)
SET color=%color%m
:repeatcolor
if [%2] NEQ [$] SET color=%color%%~2
shift
if [%2] NEQ [] if [%2] NEQ [$] SET color=%color% & goto :repeatcolor
if [%2] EQU [$] (echo %color%) else (<nul set /p ="%color%")
goto :eof

A fast alternative to color efficiently with cmd batch since Windows XP by using PowerShell as a subprocess linked to the console output through a named pipe. It can be done with FindStr too, but PowerShell offers more options and seems quicker.
The main interest in keeping PowerShell as a subprocess, using a pipe to communicate, is that the display is far more faster than launching PowerShell or FindStr for each line to display.
Other good points :
No need for temporary files
Echoing though a pipe permits the display of the full ASCII table without bothering escapes.
Works fine with fd redirection. To color only stderr as example, or to redirect to a file / other process.
Here is a sample code for doing that :
::
:: Launch a PowerShell child process in the background linked to the console and
:: earing through named pipe PowerShellCon_%PID%
::
:: Parameters :
:: [ PID ] : Console Process ID used as an identifier for the named pipe, launcher PID by default.
:: [ timeout ] : Subprocess max life in seconds, 300 by default. If -1, the subprocess
:: will not terminate while the process %PID% is still alive.
:: Return :
:: 0 if the child PowerShell has been successfully launched and the named pipe is available.
:: 1 if it fails.
:: 2 if we can't get a PID.
:: 3 if PowerShell is not present or doesn't work.
::
:LaunchPowerShellSubProcess
SET LOCALV_PID=
SET LOCALV_TIMEOUT=300
IF NOT "%~1" == "" SET LOCALV_PID=%~1
IF NOT "%~2" == "" SET LOCALV_TIMEOUT=%~2
powershell -command "$_" 2>&1 >NUL
IF NOT "!ERRORLEVEL!" == "0" EXIT /B 3
IF "!LOCALV_PID!" == "" (
FOR /F %%P IN ('powershell -command "$parentId=(Get-WmiObject Win32_Process -Filter ProcessId=$PID).ParentProcessId; write-host (Get-WmiObject Win32_Process -Filter ProcessId=$parentId).ParentProcessId;"') DO (
SET LOCALV_PID=%%P
)
)
IF "!LOCALV_PID!" == "" EXIT /B 2
START /B powershell -command "$cmdPID=$PID; Start-Job -ArgumentList $cmdPID -ScriptBlock { $ProcessActive = $true; $timeout=!LOCALV_TIMEOUT!; while((!LOCALV_TIMEOUT! -eq -1 -or $timeout -gt 0) -and $ProcessActive) { Start-Sleep -s 1; $timeout-=1; $ProcessActive = Get-Process -id !LOCALV_PID! -ErrorAction SilentlyContinue; } if ($timeout -eq 0 -or ^! $ProcessActive) { Stop-Process -Id $args; } } | Out-Null ; $npipeServer = new-object System.IO.Pipes.NamedPipeServerStream('PowerShellCon_!LOCALV_PID!', [System.IO.Pipes.PipeDirection]::In); Try { $npipeServer.WaitForConnection(); $pipeReader = new-object System.IO.StreamReader($npipeServer); while(($msg = $pipeReader.ReadLine()) -notmatch 'QUIT') { $disp='write-host '+$msg+';'; invoke-expression($disp); $npipeServer.Disconnect(); $npipeServer.WaitForConnection(); }; } Finally { $npipeServer.Dispose(); }" 2>NUL
SET /A LOCALV_TRY=20 >NUL
:LaunchPowerShellSubProcess_WaitForPipe
powershell -nop -c "& {sleep -m 50}"
SET /A LOCALV_TRY=!LOCALV_TRY! - 1 >NUL
IF NOT "!LOCALV_TRY!" == "0" cmd /C "ECHO -NoNewLine|MORE 1>\\.\pipe\PowerShellCon_!LOCALV_PID!" 2>NUL || GOTO:LaunchPowerShellSubProcess_WaitForPipe
IF "!LOCALV_TRY!" == "0" EXIT /B 1
EXIT /B 0
This "code" is written with delayed expansion ON but can be rewrite to work without it. There is many security points to consider, do not use it directly in the wild.
How to use it :
#ECHO OFF
SETLOCAL ENABLEEXTENSIONS
IF ERRORLEVEL 1 (
ECHO Extension inapplicable
EXIT /B 1
)
::
SETLOCAL ENABLEDELAYEDEXPANSION
IF ERRORLEVEL 1 (
ECHO Expansion inapplicable
EXIT /B 1
)
CALL:LaunchPowerShellSubProcess
IF NOT ERRORLEVEL 0 EXIT /B 1
CALL:Color Cyan "I write this in Cyan"
CALL:Blue "I write this in Blue"
CALL:Green "And this in green"
CALL:Red -nonewline "And mix Red"
CALL:Yellow "with Yellow"
CALL:Green "And not need to trouble with ()<>&|;,%""^ and so on..."
EXIT /B 0
:Color
ECHO -foregroundcolor %*>\\.\pipe\PowerShellCon_!LOCALV_PID!
ECHO[|SET /P=>NUL
GOTO:EOF
:Blue
ECHO -foregroundcolor Blue %*>\\.\pipe\PowerShellCon_!LOCALV_PID!
ECHO[|SET /P=>NUL
GOTO:EOF
:Green
ECHO -foregroundcolor Green %*>\\.\pipe\PowerShellCon_!LOCALV_PID!
ECHO[|SET /P=>NUL
GOTO:EOF
:Red
ECHO -foregroundcolor Red %*>\\.\pipe\PowerShellCon_!LOCALV_PID!
ECHO[|SET /P=>NUL
GOTO:EOF
:Yellow
ECHO -foregroundcolor Yellow %*>\\.\pipe\PowerShellCon_!LOCALV_PID!
ECHO[|SET /P=>NUL
GOTO:EOF
::
:: Launch a PowerShell child process in the background linked to the console and
:: earing through named pipe PowerShellCon_%PID%
::
:: Parameters :
:: [ PID ] : Console Process ID used as an identifier for the named pipe, launcher PID by default.
:: [ timeout ] : Subprocess max life in seconds, 300 by default. If -1, the subprocess
:: will not terminate while the process %PID% is still alive.
:: Return :
:: 0 if the child PowerShell has been successfully launched and the named pipe is available.
:: 1 if it fails.
:: 2 if we can't get a PID.
:: 3 if PowerShell is not present or doesn't work.
::
:LaunchPowerShellSubProcess
SET LOCALV_PID=
SET LOCALV_TIMEOUT=300
IF NOT "%~1" == "" SET LOCALV_PID=%~1
IF NOT "%~2" == "" SET LOCALV_TIMEOUT=%~2
powershell -command "$_" 2>&1 >NUL
IF NOT "!ERRORLEVEL!" == "0" EXIT /B 3
IF "!LOCALV_PID!" == "" (
FOR /F %%P IN ('powershell -command "$parentId=(Get-WmiObject Win32_Process -Filter ProcessId=$PID).ParentProcessId; write-host (Get-WmiObject Win32_Process -Filter ProcessId=$parentId).ParentProcessId;"') DO (
SET LOCALV_PID=%%P
)
)
IF "!LOCALV_PID!" == "" EXIT /B 2
START /B powershell -command "$cmdPID=$PID; Start-Job -ArgumentList $cmdPID -ScriptBlock { $ProcessActive = $true; $timeout=!LOCALV_TIMEOUT!; while((!LOCALV_TIMEOUT! -eq -1 -or $timeout -gt 0) -and $ProcessActive) { Start-Sleep -s 1; $timeout-=1; $ProcessActive = Get-Process -id !LOCALV_PID! -ErrorAction SilentlyContinue; } if ($timeout -eq 0 -or ^! $ProcessActive) { Stop-Process -Id $args; } } | Out-Null ; $npipeServer = new-object System.IO.Pipes.NamedPipeServerStream('PowerShellCon_!LOCALV_PID!', [System.IO.Pipes.PipeDirection]::In); Try { $npipeServer.WaitForConnection(); $pipeReader = new-object System.IO.StreamReader($npipeServer); while(($msg = $pipeReader.ReadLine()) -notmatch 'QUIT') { $disp='write-host '+$msg+';'; invoke-expression($disp); $npipeServer.Disconnect(); $npipeServer.WaitForConnection(); }; } Finally { $npipeServer.Dispose(); }" 2>NUL
SET /A LOCALV_TRY=20 >NUL
:LaunchPowerShellSubProcess_WaitForPipe
powershell -nop -c "& {sleep -m 50}"
SET /A LOCALV_TRY=!LOCALV_TRY! - 1 >NUL
IF NOT "!LOCALV_TRY!" == "0" cmd /C "ECHO -NoNewLine|MORE 1>\\.\pipe\PowerShellCon_!LOCALV_PID!" 2>NUL || GOTO:LaunchPowerShellSubProcess_WaitForPipe
IF "!LOCALV_TRY!" == "0" EXIT /B 1
EXIT /B 0
Link to my original answer on the same topic.

An advanced Macro for handling Cursor Color, Position and properties For Windows 10.
Please refer to the help and usage examples for information on usage.
Supports and Shows examples of:
Cursor Positioning
Absolute
Relative to last Cursor Position ; left right by n columns ; up down by n lines
Combinations of Relative and Absolute Position.
Show / Hide Cursor
Cursor Graphics properties [ Color ; Foreground and Background ]
Same line multicolor output
Easily chain multiple VT graphics sequences.
Clearing of all text on a line from a given position.
Deletion of a number of characters to the right of the cursor on the current line.
Optionally Save the Cursor position at the time of expansion as independent Y and X values.
/Save Cursor position storing component of the macro adpated from Jeb's answer here
NEW: Switching between Screen buffers.
Edit:
I've included below the final usage example a command line that uses
VT codes to achieve the same result as that example, to illustrate the
difference in readability when using multiple Terminal sequences in
the same Cursor output.
NOTES On changing Buffers:
Cursor position is tied to the active buffer; It is not availale when switching to an alternate buffer.
When reverting to the main buffer:
The cursor position originally occupied in the main buffer is restored, and the content of the alternate buffer is discarded.
::: Cout cursor Macro. Author: T3RRY ::: Filename: Cout.bat
::: OS requirement: Windows 10
::: Purpose: Facilitate advanced console display output with the easy use of Virtual terminal codes
::: Uses a macro function to effect display without users needing to memorise or learn specific
::: virtual terminal sequences.
::: Enables output of text in 255 bit color at absolute or relative Y;X positions.
::: Allows cursor to be hidden or shown during and after text output. See help for more info.
#Echo off & Setlocal EnableExtensions
============================================== :# Usage
If not "%~1" == "" Echo/%~1.|findstr /LIC:"/?" > nul && (
If "%~2" == "" (Cls & Mode 1000,50 & Color 30)
If "%~2" == "Usage" ( Color 04 & ( Echo/n|choice /n /C:o 2> nul ) & timeout /T 5 > nul )
If "%~2" == "DE" ( Color 04 & Echo/ --- Delayed expansion detected^^^! Must not be enabled prior to calling %~n0 ---&( Echo/n|choice /n /C:o 2> nul ))
If not Exist "%TEMP%\%~n0helpfile.~tmp" (For /F "Delims=" %%G in ('Type "%~f0"^| Findstr.exe /BLIC:":::" 2^> nul ')Do (
For /F "Tokens=2* Delims=[]" %%v in ("%%G")Do Echo(^|%%v^|
))>"%TEMP%\%~n0helpfile.~tmp"
Type "%TEMP%\%~n0helpfile.~tmp" | More
timeout /T 60 > nul
Color 07
If "%~2" == "DE" (Exit)Else Exit /B 1
)
If "!![" == "[" Call "%~f0" "/?" "DE"
:::[=====================================================================================================================]
:::[ cout /? ]
:::[ %COUT% Cursor output macro. ]
:::[ * Valid Args for COUT: {/Y:Argvalue} {/X:Argvalue} {/S:Argvalue} {/C:Argvalue} ]
:::[ - Args Must be encased in curly braces. Arg order does not matter ; Each Arg is optional. ]
:::[ * Valid Switches for COUT: /Save /Alt /Main ]
:::[ /Save - Stores the Y and X position at the start of the current expansion to .lY and .lX variables ]
:::[ /Alt - Switch console to alternate screen Buffer. Persists until /Main switch is used. ]
:::[ /Main - Restore console to main screen Buffer. Console default is the main buffer. ]
:::[ ]
:::[ USAGE: ]
:::[ * ArgValue Options ; '#' is an integer: ]
:::[ {/Y:up|down|#} {/Y:up#|down#|#} {/Y:#up|#down|#} {/X:left|right|#} {/X:left#|right#|#} {/X:#left|#right|#} ]
:::[ * note: {/Y:option} {/X:option} - 1 option only per Arg. ]
:::[ - directions: 'up' 'down' 'left' 'right' are relative to the cursors last position. ]
:::[ - /Y and /X options - #direction or direction#: ]
:::[ Positions the cursor a number of cells from the current position in the given direction. ]
:::[ Example; To move the cursor 5 rows up in the same column, without displaying any new text: ]
:::[ %COUT%{/Y:5up} ]
:::[ - '#' (Absolute position) is the column number {/X:#} or row number {/Y:#} the cursor ]
:::[ * Integers for absolute positions contained in variables must be Expanded: {/Y:%varname%} ]
:::[ is to be positioned at, allowing cursor position to be set on single or multiple axis. ]
:::[ * Absolute Y and X positions capped at line and column maximum of the console display. ]
:::[ * Exceeding the maximum Y positions the cursor at the start of the last line in the console display. ]
:::[ * Exceeding the maximum X positions the cursor at the start of the next line ]
:::[ ]
:::[ {/S:Output String} {/S:(-)Output String} {/S:Output String(+)} {/S:Output String(K)} {/S:Output String(.#.)} ]
:::[ * note: (-) Hide or (+) Show the Cursor during output of the string. ]
:::[ (K) Clears the row of text from the position (K) occurs. ]
:::[ Example; Delete 5 characters from the current row to the right of the curser: ]
:::[ %COUT%{/S:(.5.)} ]
:::[ {/C:VTcode} {/C:VTcode-VTcode} {/C:VTcode-VTcode-VTcode} ]
:::[ * note: Chain multiple graphics rendition codes using '-' ]
:::[ See: https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#text-formatting ]
:::[ See also: https://www.rapidtables.com/web/color/RGB_Color.html ]
:::[=====================================================================================================================]
============================================== :# PreScript variable definitions
rem /* generate Vitual Terminal Escape Control .Character */
For /F %%a in ( 'Echo prompt $E ^| cmd' )Do Set "\E=%%a"
rem /* https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences */
(Set \n=^^^
%= Newline variable for macro definitions. DO NOT MODIFY this line or above 2 lines. =%)
================== :# Screen Dimensions [Customise columns,lines using the mode command.]
Mode 160,38 & Cls
rem /* Get screen dimensions [lines] [columns]. Must be done before delayed expansion is enabled. */
For /F "tokens=1,2 Delims=:" %%G in ('Mode')Do For %%b in (%%H)Do For %%a in (%%G)Do Set "%%a=%%b"
rem /* NON ENGLISH VERSION USERS: You will need to manually set Columns and lines for their desired console size */
If not defined columns (Set "columns=100"& Set "lines=30")
rem /* Cursor position codes - https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#simple-cursor-positioning */
Set "left=D"&Set "right=C"&Set "up=A"&set "down=B"
For /L %%n in (1 1 %lines%)Do (Set "%%ndown=[%%nB"&Set "down%%n=[%%nB"& set "%%nup=[%%nA"&Set "up%%n=[%%nA")
For /L %%n in (1 1 %columns%)Do (Set "%%nleft=[%%nD"&Set "left%%n=[%%nD"&set "%%nright=[%%nC"&set "right%%n=[%%nC")
%= Catch Args =%Set COUT=For %%n in (1 2)Do If %%n==2 ( %\n%
%= Test No Args =%If "!Args!" == "" (CLS^&Echo/Usage Error. Args Required. ^& Call "%~f0" "/?" "Usage" ^|^| Exit /B 1) %\n%
%= Test Braces Used =%If "!Args:}=!" == "!Args!" (CLS^&Echo/Usage Error. Args must be enclosed in curly braces ^& Call "%~f0" "/?" "Usage" ^|^| Exit /B 1) %\n%
%= Reset macro =%Set ".Y=" ^& Set ".X=" ^& Set ".Str=" ^& Set ".C=" %\n%
%= internal vars =%Set "Arg1=" ^& Set "Arg2=" ^& Set "Arg3=" ^& Set "Arg4=" %\n%
%= Split Args. =%For /F "Tokens=1,2,3,4 Delims={}" %%1 in ("!Args!")Do ( %\n%
%= Substring =%Set "Arg1=%%~1" %\n%
%= modification =%Set "Arg2=%%~2" %\n%
%= identifies Args =%Set "Arg3=%%~3" %\n%
%= during handling. =%Set "Arg4=%%~4" %\n%
%= =%) %\n%
%= Check /Save switch =%If not "!Args:/Save=!" == "!Args!" (%\n%
%= Reset Cursor Save =%Set ".Cpos=" ^&Set ".Char="%\n%
%= 10 char max; Repeat =%For /L %%l in (2 1 12)Do (%\n%
%= until R returned =%If not "!.Char!" == "R" (%\n%
%= from esc[6n =%^<nul set /p "=%\E%[6n" %\n%
%= Redirects to =%FOR /L %%z in (1 1 %%l) DO pause ^< CON ^> NUL%\n%
%= prevent blocking =%Set ".Char=;"%\n%
%= script execution =%for /F "tokens=1 skip=1 delims=*" %%C in ('"REPLACE /W ? . < con"') DO (Set ".Char=%%C")%\n%
%= Append string w.out R =%If "!.Cpos!" == "" (Set ".Cpos=!.Char!")Else (set ".Cpos=!.Cpos!!.Char:R=!") %\n%
%= =%)%\n%
%= =%)%\n%
%= Split Captured Pos =%For /F "tokens=1,2 Delims=;" %%X in ("!.Cpos!")Do Set ".lY=%%X" ^& Set ".LX=%%Y" %\n%
%= End of Pos /Save =%)%\n%
%= Begin Arg =%For %%i in (1 2 3 4)Do For %%S in (Y X C S)Do If not "!Arg%%i!" == "" ( %\n%
%= Processing. 4 Args =%If not "!Arg%%i:/%%S:=!" == "!Arg%%i!" ( %\n%
%= Flagged with Y X C S =%Set "Arg%%i=!Arg%%i:/%%S:=!" %\n%
%= Strip /Flag In Arg# =%For %%v in ("!Arg%%i!")Do ( %\n%
%= /Y Lines Arg handling =%If "%%S" == "Y" ( %\n%
%= Test if arg is variable =%If Not "!%%~v!" == "" ( %\n%
%= assign down / up value =%Set ".Y=%\E%!%%~v!" %\n%
%= -OR- =%)Else ( %\n%
%= assign using operation =%Set /A ".Y=!Arg%%i!" %\n%
%= to allow use of offsets; =%If !.Y! GEQ !Lines! (Set /A ".Y=Lines-1") %\n%
%= constrained to console =%Set ".Y=%\E%[!.Y!d" %\n%
%= maximum lines. =%)) %\n%
%= /X Cols Arg handling =%If "%%S" == "X" ( %\n%
%= processing follows same =%If Not "!%%~v!" == "" ( %\n%
%= logic as /Y; =%Set ".X=%\E%!%%~v!" %\n%
%= except if Columns =%)Else ( %\n%
%= exceed console max =%Set /A ".X=!Arg%%i!" %\n%
%= columns line wrapping =%If !.X! GEQ !Columns! (Set ".X=1"^& Set ".Y=%\E%!Down!") %\n%
%= is effected. =%Set ".X=%\E%[!.X!G" %\n%
%= =%)) %\n%
%= /C Color Arg Handling. %If "%%S" == "C" ( %\n%
%= Substituition =%Set ".C=%\E%[!Arg%%i!" %\n%
%= replaces '-' with VT =%Set ".C=!.C:-=m%\E%[!" %\n%
%= chain - m\E[ =%Set ".C=!.C!m" %\n%
%= =%) %\n%
%= /S String Arg Handle =%If "%%S" == "S" ( %\n%
%= Substitute Sub-Args =%Set ".Str=!Arg%%i!" %\n%
%= (-) hide cursor =%Set ".Str=!.Str:(-)=%\E%[?25l!" %\n%
%= (+) show cursor =%Set ".Str=!.Str:(+)=%\E%[?25h!" %\n%
%= (K) clear line =%Set ".Str=!.Str:(K)=%\E%[K!" %\n%
%= (.#.) delete # of =%Set ".Str=!.Str:(.=%\E%[!" %\n%
%= characters =%Set ".Str=!.Str:.)=P!" %\n%
%= =%) %\n%
%= End Arg Handling =%))) %\n%
%= /Main /Alt Switch =%If not "!Args:/Main=!" == "!Args!" ( %\n%
%= handling for =%^< nul Set /P "=%\E%[?1049l!.Y!!.X!!.C!!.Str!%\E%[0m" %\n%
%= switching console =%)Else If not "!Args:/Alt=!" == "!Args!" ( %\n%
%= buffers. No Switch =%^< nul Set /P "=%\E%[?1049h!.Y!!.X!!.C!!.Str!%\E%[0m" %\n%
%= outputs to current =%)Else ( ^< nul Set /P "=!.Y!!.X!!.C!!.Str!%\E%[0m" ) %\n%
%= buffer. =%)Else Set Args=
rem /* Simple subsecond delay macro. Uses call to a non existentent label # number of times to delay script execution. */
For /F "tokens=1,2 delims==" %%G in ('wmic cpu get maxclockspeed /format:value')Do Set /A "%%G=%%H/20" 2> nul
If not defined Maxclockspeed Set "Maxclockspeed=200"
Set "Hash=#"& Set "delay=(If "!Hash!" == "#" (Set /A "Delay.len=Maxclockspeed")Else Set "Delay.len=#")& For /L %%i in (1 1 !Delay.Len!)Do call :[_false-label_] 2> Nul"
============================================== :# Script Body [Demo]
rem /* Enable Delayed Expansion after macro definiton in order to expand macro. */
Setlocal EnableDelayedExpansion & CD "%TEMP%"
rem /* Usage examples */
%COUT%{/X:10}{/Y:5}{/C:34}{"/S:(-)hello there^^^!"}
%Delay%
rem /* Example use of mixed foreground / background color and other graphics rendition properties */
%COUT%{"/C:31-1-4-48;2;0;80;130"}{/S:Bye for now.}{/Y:down}
%Delay%
%COUT%{/Y:up}{/C:35}{/S:again}{/X:16}
%Delay%
%COUT%{"/S:(K)^_^"}{/X:right}{/C:32}{/Y:down} /Save
%Delay%
rem /* Switch to Alternate screen buffer: /Alt */
%COUT%{"/S:(-)(K)o_o"}{/X:.lX+1}{/Y:6}{/C:33}{/Y:down} /Alt
%Delay%
%COUT%{"/S:Don't worry, they'll be back"}{/Y:down}{/X:15left}{/C:7-31}
rem /* Cursor position is tied to the active console buffer. The contents of the Alternate buffer are discarded when reverting to the Main buffer. */
%Delay%
rem /* Return to Main screen buffer: /Main */
%COUT%{/X:3left}{/Y:5up}{"/S:That's all folks."} /Save /Main
rem /* Cursor position is tied to the active console buffer. */
%Delay%
rem /* restore cursor position /Save .lX value with +7 offset ; Overwrite all and delete 6 following characters:(.6.) ; restore cursor: (+) */
%COUT%{/X:10left}{/S:How(.6.)(+)}{/C:32}
rem /* The same as the above line using VT codes manually. */
::: <nul Set /P "=%\E%[10D%\E%[32mHow%\E%[6P%\E%[?25l"
%Delay%
%COUT%{/Y:100}
Endlocal
Goto :eof
An alternate version of the above macro that uses a structure for arg handling that is simpler and has better readability can be found here.

I just converted from Win 7 Home to Win 10 Pro and wanted to replace the batch I call from other batches to echo info in color. Reviewing what is discussed above I use the following which will directly replace my previous batch. NOTE the addition of "~" to the message so that messages with spaces may be used. Instead of remembering codes I use letters for the colors I needed.
If %2 contains spaces requires "..."
%1 Strong Colors on black: R=Red G=GREEN Y=YELLOW W=WHITE
ECHO OFF
IF "%1"=="R" ECHO ^[91m%~2[0m
IF "%1"=="G" ECHO ^[92m%~2[0m
IF "%1"=="Y" ECHO ^[93m%~2[0m
IF "%1"=="W" ECHO ^[97m%~2[0m

for me i found some solutions: it is a working solution
#echo off
title a game for youtube
explorer "https://thepythoncoding.blogspot.com/2020/11/how-to-echo-with-different-colors-in.html"
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
echo say the name of the colors, don't read
call :ColorText 0a "blue"
call :ColorText 0C "green"
call :ColorText 0b "red"
echo(
call :ColorText 19 "yellow"
call :ColorText 2F "black"
call :ColorText 4e "white"
goto :Beginoffile
:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
:Beginoffile

Put the following lines into a file called ColourText.bas on your desktop.
Imports System
Imports System.IO
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Public Module MyApplication
Public Declare Function GetStdHandle Lib "kernel32" Alias "GetStdHandle" (ByVal nStdHandle As Long) As Long
Public Declare Function SetConsoleTextAttribute Lib "kernel32" Alias "SetConsoleTextAttribute" (ByVal hConsoleOutput As Long, ByVal wAttributes As Long) As Long
Public Const STD_ERROR_HANDLE = -12&
Public Const STD_INPUT_HANDLE = -10&
Public Const STD_OUTPUT_HANDLE = -11&
Sub Main()
Dim hOut as Long
Dim Ret as Long
Dim Colour As Long
Dim Colour1 As Long
Dim Text As String
hOut = GetStdHandle(STD_OUTPUT_HANDLE)
Colour = CLng("&h" & Split(Command(), " ")(0))
Colour1 = Clng("&h" & Split(Command(), " ")(1))
Text = Mid(Command(), 7)
Ret = SetConsoleTextAttribute(hOut, Colour)
Console.Out.WriteLine(text)
Ret = SetConsoleTextAttribute(hOut, Colour1)
End Sub
End Module
Save it and type the following in a command prompt.
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:exe /out:"%userprofile%\desktop\ColourText.exe" "%userprofile%\desktop\ColourText.bas" /verbose
A file called ColourText.exe will appear on your desktop. Move it to the Windows folder.
To use you must use two character codes to set colour eg 01 not 1.
ColourText ColourOfText ColourOfTextWhenFinished Text
EG To set blue on white by not passing any text, then red on white text, finishing with blue on grey.
ColourText F1 F1
ColourText F2 71 This is green on white
or
ColourText F1 F1
cls
ColourText F4 F4
Echo Hello
Echo Hello today
ColourText F1 F1
Also the CLS command becomes interesting. Color command without parameters resets all colours to startup colours.
To get the colour code add the following numbers together. Use Calculator in programmers mode. These are hex numbers. They can be added together eg Red + Blue + FG Intensity = 13 = D. As 10+ wasn't used the background will be black. Colour codes MUST be two characters, eg 08 not 8.
FOREGROUND_RED = &H4 ' text color contains red.
FOREGROUND_INTENSITY = &H8 ' text color is intensified.
FOREGROUND_GREEN = &H2 ' text color contains green.
FOREGROUND_BLUE = &H1 ' text color contains blue.
BACKGROUND_BLUE = &H10 ' background color contains blue.
BACKGROUND_GREEN = &H20 ' background color contains green.
BACKGROUND_INTENSITY = &H80 ' background color is intensified.
BACKGROUND_RED = &H40 ' background color contains red.

To get this working on Windows 10, you can enable this flag: ENABLE_VIRTUAL_TERMINAL_PROCESSING.
With this registry key you can set this by default
[HKCU\Console] VirtualTerminalLevel dword 0x1

An alternative is to use NodeJS.
Here is an example:
const os = require('os');
const colors = require('colors');
console.log("Operative System:".green,os.type(),os.release());
console.log("Uptime:".blue,os.uptime());
And this is the result:

Setting color to the log statements in powershell is not a big deal friend.
you can use -ForegroundColor parameter.
To write a confirmation message.
Write-Host "Process executed Successfully...." -ForegroundColor Magenta
To write an error message.
Write-Host "Sorry an unexpected error occurred.." -ForegroundColor Red
To write a progress message.
Write-Host "Working under pocess..." -ForegroundColor Green

call :color_echo "blue" "blue txt"
call :color_echo "red" "red txt"
echo "white txt"
REM : https://www.robvanderwoude.com/ansi.php
:color_echo
#echo off
set "color=%~1"
set "txt=%~2"
set ESC=
set black=%ESC%[30m
set red=%ESC%[31m
set green=%ESC%[32m
set yellow=%ESC%[33m
set blue=%ESC%[34m
set magenta=%ESC%[35m
set cyan=%ESC%[36m
set white=%ESC%[37m
if "%~1" == "black" set "color=!black!"
if "%~1" == "red" set "color=!red!"
if "%~1" == "green" set "color=!green!"
if "%~1" == "yellow" set "color=!yellow!"
if "%~1" == "blue" set "color=!blue!"
if "%~1" == "magenta" set "color=!magenta!"
if "%~1" == "cyan" set "color=!cyan!"
if "%~1" == "white" set "color=!white!"
echo | set /p="!color!!txt!"
echo.
REM : return to standard white color
echo | set /p="!white!"
REM : exiting the function only
EXIT /B 0

Easiest way is make a system call to powershell like this :
s=os.system('powershell Write-Host "I am so bored with this. Work already" -ForegroundColor Blue')
otherwise :
←[94mPff

You can use the color command to change the color of the whole console
Color 0F
Is black and white
Color 0A
Is black and green

Related

How do I put double spaces in batch file variables?

So, I've been trying to write games using batch files, and typically I write something like
set a-1-1= &set a-1-2=
set a-2-1= &set a-2-2=
, then to access it I use
set a-%x%-%y%=11
The problem is I can't store a double space in these variables.
It would be very helpful to know what your use case is - the type of game you are attempting to make, the output you are trying to achieve, how you intend to use the array.
Is it just for output? For Collision Detection?
As regards to options for defining and using arrays in batch, familiarise yourself with Delayed expansion, For loops and substring modificiation - as they are batches best tools for the job.
Open cmd.exe and read the output of:
Setlocal /?
Set /?
for /?
Delayed expansion allows for a neat little trick where you can define commands that reference array values before the values are actually assigned by Defining them with ! expansion prior to actually enabling Delayed Expansion. Such Commands as variables in Batch are refered to as Macros.
Here's an example of using defining and using arrays via batch macro's within a game of Tic Tac Toe.
:start ::: [ * Author: T3RRY * ] Creation Date - 12/01/2021 ::: WINDOWS 10 only
#Echo off & mode 50,11
:# Define Virtual Termnal Escape Character. Requires Windows 10
For /F %%a in ('echo prompt $E ^| cmd')do Set "\E=%%a"
Set LF=^
%= ! linefeed var. Do not remove or modify this line or above 2 lines ! =%
:# Clear the screen and Define the GRID macro for display of the playfield
CLS & Set "Grid=<nul Set /P "=%\E%[2;13H%\E%[37mDraw %\E%[34mWin %\E%[33mLose%\E%[5;1H!Spacer!%\E%[?25l%\E%[0m%\E%[35m%\E%[0m%\E%[35m[%\E%[90m!c7:7=%\E%[7m7!%\E%[0m%\E%[35m][%\E%[90m!c8:8=%\E%[7m8!%\E%[0m%\E%[35m][%\E%[90m!c9:9=%\E%[7m9!%\E%[0m%\E%[35m]!LF!!Spacer![%\E%[90m!c4:4=%\E%[7m4!%\E%[0m%\E%[35m][%\E%[90m!c5:5=%\E%[7m5!%\E%[0m%\E%[35m][%\E%[90m!c6:6=%\E%[7m6!%\E%[0m%\E%[35m]!LF!!Spacer![%\E%[90m!c1:1=%\E%[7m1!%\E%[0m%\E%[35m][%\E%[90m!c2:2=%\E%[7m2!%\E%[0m%\E%[35m][%\E%[90m!c3:3=%\E%[7m3!%\E%[0m%\E%[35m]%\E%[0m""
:# Define reset macro used to flag game end state and reset the enviroment for next game
Set "Reset=( Title #. Game over. ) & Timeout /t 3 /Nobreak > nul & Endlocal & Goto :start"
:# Defines a Macro to Iterate over winning cells ; used in assesing moves and gamestate
Set "?.Cells=For %%V in ("!c1!!c4!!c7!" "!c2!!c5!!c8!" "!c3!!c6!!c9!" "!c1!!c2!!c3!" "!c4!!c5!!c6!" "!c7!!c8!!c9!" "!c3!!c5!!c7!" "!c1!!c5!!c9!")Do "
:# Enable Environment for Macro Expansion
Setlocal EnableExtensions EnableDelayedExpansion
:# Define custom or Default Characters for Player 1 and AI
If not "%~2" == "" (
Set "P1=%~1"& Set "P2=%~2"& Set "P1=!P1:~-1!"& Set "P2=!P2:~-1!"
)Else ( Set "P1=X"& Set "P2=O" )
:# Define Move List 'Cho' and initial Cell state for c1 - c9
Set "Cho= 123456789"& Set "turn=9"& For /L %%n in (1 1 9)Do Set "c%%n=%%n"
:# Offset playfield from screen Edge [used in Grid Macro]
For /L %%n in (1 1 20)Do Set "Spacer= !Spacer!"
:# Randomise starting Player
For /F "Delims=" %%v in ('set /A "!random! %%2 + 1"')Do Goto p%%v
:p1
%GRID% & TITLE Enter a number - Available: %Cho% or [E]xit
For /F "Delims=" %%G in ('Choice /N /C:%Cho: =%e')Do (
Set "c%%G=!P1!"
Set "Cho=!Cho:%%G=!"
Set /A turn-=1
If %%G == E Exit /b 0
)
%GRID:90=32% & Call :Delay 2> nul
:p2
TITLE Tic Tac Toe & %?.Cells% If "%%~V" == "!p1!!p1!!p1!" Goto :Win
Set "move=" & Set "line="
%?.Cells% For %%c in (!P1! !P2!)Do (
Set "line=%%~V"
For /L %%n in (1 1 9)Do ( :# Test ideal move; Priority - Take win ; block player
Set "line=!line:%%n%%c%%c=!"
If not "!line!" == "" Set "line=!line:%%c%%n%%c=!"
If not "!line!" == "" Set "line=!line:%%c%%c%%n=!"
If "!line!" == "" (Set "move=%%n")
))
Call :AI "!P2!" && %GRID:90=31% & Call :Delay 2> nul
%?.Cells% If "%%~V" == "!p2!!p2!!p2!" Goto :Lose
If !turn! LEQ 0 ( %GRID:90=37% & %Reset:#=Draw% )Else Goto p1
:AI [ Enact best available move option win; block player win; centre; random ]
If not "%move%" == "" (
Set "c%move%=%~1"
Set "Cho=!Cho:%move%=!"
Set /A "turn-=1"
Exit /B 0
)
Set "tCho=!Cho:5=!"
If Not "!tCho!" == "!Cho!" (
Set "c5=%~1"
Set "Cho=!Cho:5=!"
Set /A "turn-=1"
Exit /B 0
)
For /F "Delims=" %%v in ('set /A "!random! %%!turn! + 1" 2^> nul ')Do (
For %%i in ("!Cho:~%%v,1!")Do If not "!Cho:~%%v,1!" == " " If "!c%%~i!" == "%%~i" (
Set "c%%~i=%~1" & Set "Cho=!Cho:%%~i=!" & Set /A "turn-=1"
Exit /B 0
))
If !turn! EQU 0 (Exit /B 0)Else Goto :AI
:Win
%Grid:90=34% & %Reset:#=You Won%
:Lose
%Grid:90=33% & %Reset:#=You Lost%
The Display macro Grid Is defined referencing the array variables for the Grid Move state. As Moves are made, Occupied cells c1 to c9 are redifined. Because the macro is defined using delayed expansion to expand the variables, but before to Delayed Expansion is actually enabled, when the macro is expanded, it expands with the current value of the c1 to c9 cel array.
Substring modification is used to update the information displayed in the Grid Array after each change.
Substring modification is also used in conjunction with An if condition to compare winning cell lines Defined in the ?Cells macro against the definitions of the current cell array to see if lines are complete or alost complete as a means of determining move action and gamestate.

Batch file to change color of text depending on output string from log file

I'm trying to read a log file with a batch file.
If the batch file finds SUCCESS in the log file, the text should be in green.
If the batch file finds WARNING in the log file, the text should be in cyan.
If the batch file finds ERROR in the log file, the text should be in red.
It works when it finds either of the one value, but if the log file contains two or more of the different results like SUCCESS and WARNING it doesn't work.
Trying to read a log file with batch file on Windows.
#echo off
set LogPath=C:\Mworks\logs
set /p MM-DD="Enter Month and Day (MM-DD) to Search logs for success close eg. 08-24: "
set YEAR=2019
#echo searching for %LogPath%\%YEAR%-%MM-DD%*.log
FOR /F "eol=- tokens=1-8 delims= " %%i in ('find /I "LOG ROTATE COMPLETE" %LogPath%\%YEAR%-%MM-DD%*.log') do set result=%%p
echo %result%
(
IF /I %result%==ERROR (goto :ERROR)
)
(
if /I %result%==SUCCESS (goto :SUCCESS)
)
(
if /I %result%==WARNING (goto :WARNING)
)
REM somehow need to catch value at token 8 and color the lines accordingly
REM proper use of enableDelayedExpansion might help but it's quite tough simply with batch script.
REM I've seen hackoo's version of pinger doing it but the code is hard to understand, which part controls what.
:SUCCESS
color 0A
REM this line needs to be on GREEN
FOR /F "eol=- tokens=1-8 delims= " %%i in ('find /I "LOG ROTATE COMPLETE" %LogPath%\2019-%MM-DD%*.log') do #echo %%i %%j %%k %%l %%m %%n %%o %%p
goto end
:ERROR
color 0C
REM this line nees to be on RED
FOR /F "eol=- tokens=1-8 delims= " %%i in ('find /I "LOG ROTATE COMPLETE" %LogPath%\2019-%MM-DD%*.log') do #echo %%i %%j %%k %%l %%m %%n %%o %%p
goto end
:WARNING
REM This line needs to be on CYAN
color 0B
FOR /F "eol=- tokens=1-8 delims= " %%i in ('find /I "LOG ROTATE COMPLETE" %LogPath%\2019-%MM-DD%*.log') do #echo %%i %%j %%k %%l %%m %%n %%o %%p
:end
pause
The code doesn't work if it find more than one result where result could be SUCCESS, WARNING, ERROR.
**LOG BEGUN 2019-08-24 03:42:28,662
loading c:Mworksconfiglog4j2.xml
INFO 2019-08-24 03:42:34,100 Initializing configs... :: oracle.retail.mworks.config.mworksProperties [mworks]
INFO 2019-08-24 03:42:34,100 Loading Properties - jar:file:/C:/Mworks/lib/menv-engine.jar!/dtv/res/config/actions.properties :: dtv.util.ResourceUtils [mworks]
INFO 2019-08-24 03:42:34,115 Loading Properties - file:/C:/Mworks/cust_config/version1/actions.properties :: dtv.util.ResourceUtils [mworks]
INFO 2019-08-24 03:42:34,131 Loading Properties - jar:file:/C:/Mworks/lib/menv-engine.jar!/dtv/res/config/environment.properties :: dtv.util.ResourceUtils [mworks]
INFO 2019-08-24 03:42:34,131 Loading Properties - file:/C:/Mworks/cust_config/version1/environment.properties :: dtv.util.ResourceUtils [mworks]
INFO 2019-08-24 03:42:34,146 Loading Properties - jar:file:/C:/Mworks/lib/menv-engine.jar!/dtv/res/config/update.properties :: dtv.util.ResourceUtils [mworks]
INFO 2019-08-24 03:42:34,162 Loading Properties - file:/C:/Mworks/cust_config/version1/update.properties :: dtv.util.ResourceUtils [mworks]
INFO 2019-08-24 03:42:34,162 Loading Properties - jar:file:/C:/Mworks/lib/menv-engine.jar!/dtv/res/config/local.properties :: dtv.util.ResourceUtils [mworks]
INFO 2019-08-24 03:42:34,162 Loading Properties - file:/C:/Mworks/cust_config/version1/local.properties :: dtv.util.ResourceUtils [mworks]
INFO 2019-08-24 03:42:34,584 Loading registration data from c:\Mworks\res\data\registrationdata.json :: oracle.retail.mworks.registration.RegistrationDataManager [mworks]
INFO 2019-08-24 03:42:35,287 Gathering local Client data. :: oracle.retail.mworks.registration.RegistrationDataManager [mworks]
INFO 2019-08-24 03:42:36,334 loading jar:file:/C:/Mworks/lib/menv-engine.jar!/dtv/res/config/MBeanInfoConfig.xml :: dtv.util.config.ConfigHelper [mworks]
INFO 2019-08-24 03:42:36,883
INFO 2019-08-24 03:42:36,883 Waiting for services to start... :: oracle.retail.mworks.mworks [mworks]
ntly running actions: [startup-lead, create-update-directories, LOG ROTATE] :: oracle.retail.mworks.action.Action [ActionExec-1]
INFO 2019-08-24 03:42:40,447 Action [CreateUpdateDirectories :: oracle.retail.mworks.atoms.CreateUpdateDirectories] complete. State: SUCCESS, Result: -----------------------------------
The text below should be in RED
----------------------------------
INFO 2019-08-24 03:42:40:03,060 LOG ROTATE complete. Status: ERROR Created update directories. :: oracle.retail.mworks.atoms.Atom [ActionExec-1]
INFO 2019-08-24 03:42:40,447 Currently running actions: [startup-lead, LOG ROTATE] :: oracle.retail.mworks.action.Action [ActionExec-1]
INFO 2019-08-24 03:42:40,447 Action [create-update-directories] returned state [SUCCESS] with message [Created update directories.] ::
The text below should be in cyan
---------------------------------------
INFO 2019-08-24 04:44:03,060 LOG ROTATE complete. Status: WARNING
LOT OF lines DELETED
The text below should be in green
----------------------------------------
INFO 2019-08-24 05:44:03,060 LOG ROTATE complete. Status: SUCCESS :: oracle.retail.xenvironment.action.Action [ActionExec-2]
sample log
This is my mono color output
something like this:
#Echo Off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
call :chooseColor 0A "This is colored Green means SUCCESS"
echo.
call :chooseColor 0B "This is colored Cyan means WARNING"
echo.
call :chooseColor 0C "This is colored Red means ERROR"
echo.
pause
goto eof
:chooseColor
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i
:eof
output should be like this
A pure batch solution using ANSI Escape codes requires a more recent Win10 version.
Difficulty is the ESC symbol hex 0x1b, dec 27 which not all editors provide easily.
Here solved using certutil to convert hex to binary.
EDIT stacked a for to the for /f with a lowercase %%f
:: Q:\Test\2019\08\31\SO_57736435.cmd
#echo off
:restart
set "MM-DD="
set /p MM-DD="Enter Month and Day (MM-DD) to Search logs for success close eg. 08-24: "
if not defined MM-DD Exit /B 0
set "LogPath=C:\Mworks\logs"
set "File=%LogPath%\log.2019-%MM-DD%*.log"
if not exist "%File%" (Echo %File% doesn't exist&pause&goto :restart)
:: ANSI Escape codes, supported with Win10 again
Call :GetCSI
FOR %%f in ("%File%") Do FOR /F "usebackq tokens=1-8* delims= " %%A in ("%%f"
) do if /I "%%A%%D%%E%%F%%G"=="INFOLogRotateComplete.Status:" (
Call :%%H "%%A %%B %%C %%D %%E %%F %%G %%H %%I"
) Else (
Echo:%%A %%B %%C %%D %%E %%F %%G %%H %%I
)
Pause
exit /B 0
:Warning
Echo(%CSI%36m%~1%CSI%0m
Goto :Eof
:Success
Echo(%CSI%32m%~1%CSI%0m
Goto :Eof
:Error
Echo(%CSI%31m%~1%CSI%0m
Goto :Eof
:GetCSI
echo 1B 5B>CSI.hex
Del CSI.bin >NUL 2>&1
certutil -decodehex CSI.hex CSI.bin >NUL 2>&1
Set /P CSI=<CSI.bin
Goto :Eof
Batch is definitely the wrong script language for this, you need:
full featured Regular Expression support
the capability to easily color single lines
BTW your batch has a bunch of errors/shortcummings
This PowerShell script (using a single fixed file name) should do what you are after:
## create a hash table with the color mappings
$FG = #{SUCCESS='green';WARNING='cyan';ERROR='red'}
# Regular Expression with a capture group to grep
# the Status, see https://regex101.com/r/d0swXC/1
$RE = '^INFO (.*?) LOG ROTATE complete\. +Status: (?<Status>[^ ]+).*'
ForEach($Line in Get-Content .\file.log){
if ($Line -match $RE){
Write-Host -ForegroundColor $FG[$Matches.Status] $Line
} Else {
Write-Host $Line
}
}
A fast alternative to color efficiently with cmd batch since Windows XP by using PowerShell as a subprocess linked to the console output through a named pipe. It can be done with FindStr too, but PowerShell offers more options and seems quicker.
The main interest in keeping PowerShell as a subprocess, using a pipe to communicate, is that the display is far more faster than launching PowerShell or FindStr for each line to display.
Other good points :
No need for temporary files
Echoing though a pipe permits the display of the full ASCII table without bothering escapes.
Works fine with fd redirection. To color only stderr as example, or to redirect to a file / other process.
Here is a sample code for doing that :
::
:: Launch a PowerShell child process in the background linked to the console and
:: earing through named pipe PowerShellCon_%PID%
::
:: Parameters :
:: [ PID ] : Console Process ID used as an identifier for the named pipe, launcher PID by default.
:: [ timeout ] : Subprocess max life in seconds, 300 by default. If -1, the subprocess
:: will not terminate while the process %PID% is still alive.
:: Return :
:: 0 if the child PowerShell has been successfully launched and the named pipe is available.
:: 1 if it fails.
:: 2 if we can't get a PID.
:: 3 if PowerShell is not present or doesn't work.
::
:LaunchPowerShellSubProcess
SET LOCALV_PID=
SET LOCALV_TIMEOUT=300
IF NOT "%~1" == "" SET LOCALV_PID=%~1
IF NOT "%~2" == "" SET LOCALV_TIMEOUT=%~2
powershell -command "$_" 2>&1 >NUL
IF NOT "!ERRORLEVEL!" == "0" EXIT /B 3
IF "!LOCALV_PID!" == "" (
FOR /F %%P IN ('powershell -command "$parentId=(Get-WmiObject Win32_Process -Filter ProcessId=$PID).ParentProcessId; write-host (Get-WmiObject Win32_Process -Filter ProcessId=$parentId).ParentProcessId;"') DO (
SET LOCALV_PID=%%P
)
)
IF "!LOCALV_PID!" == "" EXIT /B 2
START /B powershell -command "$cmdPID=$PID; Start-Job -ArgumentList $cmdPID -ScriptBlock { $ProcessActive = $true; $timeout=!LOCALV_TIMEOUT!; while((!LOCALV_TIMEOUT! -eq -1 -or $timeout -gt 0) -and $ProcessActive) { Start-Sleep -s 1; $timeout-=1; $ProcessActive = Get-Process -id !LOCALV_PID! -ErrorAction SilentlyContinue; } if ($timeout -eq 0 -or ^! $ProcessActive) { Stop-Process -Id $args; } } | Out-Null ; $npipeServer = new-object System.IO.Pipes.NamedPipeServerStream('PowerShellCon_!LOCALV_PID!', [System.IO.Pipes.PipeDirection]::In); Try { $npipeServer.WaitForConnection(); $pipeReader = new-object System.IO.StreamReader($npipeServer); while(($msg = $pipeReader.ReadLine()) -notmatch 'QUIT') { $disp='write-host '+$msg+';'; invoke-expression($disp); $npipeServer.Disconnect(); $npipeServer.WaitForConnection(); }; } Finally { $npipeServer.Dispose(); }" 2>NUL
SET /A LOCALV_TRY=20 >NUL
:LaunchPowerShellSubProcess_WaitForPipe
powershell -nop -c "& {sleep -m 50}"
SET /A LOCALV_TRY=!LOCALV_TRY! - 1 >NUL
IF NOT "!LOCALV_TRY!" == "0" cmd /C "ECHO -NoNewLine|MORE 1>\\.\pipe\PowerShellCon_!LOCALV_PID!" 2>NUL || GOTO:LaunchPowerShellSubProcess_WaitForPipe
IF "!LOCALV_TRY!" == "0" EXIT /B 1
EXIT /B 0
This "code" is written with delayed expansion ON but can be rewrite to work without it. There is many security points to consider, do not use it directly in the wild.
How to use it :
#ECHO OFF
SETLOCAL ENABLEEXTENSIONS
IF ERRORLEVEL 1 (
ECHO Extension inapplicable
EXIT /B 1
)
::
SETLOCAL ENABLEDELAYEDEXPANSION
IF ERRORLEVEL 1 (
ECHO Expansion inapplicable
EXIT /B 1
)
CALL:LaunchPowerShellSubProcess
IF NOT ERRORLEVEL 0 EXIT /B 1
CALL:Color Cyan "I write this in Cyan"
CALL:Blue "I write this in Blue"
CALL:Green "And this in green"
CALL:Red -nonewline "And mix Red"
CALL:Yellow "with Yellow"
CALL:Green "And not need to trouble with ()<>&|;,%""^ and so on..."
EXIT /B 0
:Color
ECHO -foregroundcolor %*>\\.\pipe\PowerShellCon_!LOCALV_PID!
ECHO[|SET /P=>NUL
GOTO:EOF
:Blue
ECHO -foregroundcolor Blue %*>\\.\pipe\PowerShellCon_!LOCALV_PID!
ECHO[|SET /P=>NUL
GOTO:EOF
:Green
ECHO -foregroundcolor Green %*>\\.\pipe\PowerShellCon_!LOCALV_PID!
ECHO[|SET /P=>NUL
GOTO:EOF
:Red
ECHO -foregroundcolor Red %*>\\.\pipe\PowerShellCon_!LOCALV_PID!
ECHO[|SET /P=>NUL
GOTO:EOF
:Yellow
ECHO -foregroundcolor Yellow %*>\\.\pipe\PowerShellCon_!LOCALV_PID!
ECHO[|SET /P=>NUL
GOTO:EOF
::
:: Launch a PowerShell child process in the background linked to the console and
:: earing through named pipe PowerShellCon_%PID%
::
:: Parameters :
:: [ PID ] : Console Process ID used as an identifier for the named pipe, launcher PID by default.
:: [ timeout ] : Subprocess max life in seconds, 300 by default. If -1, the subprocess
:: will not terminate while the process %PID% is still alive.
:: Return :
:: 0 if the child PowerShell has been successfully launched and the named pipe is available.
:: 1 if it fails.
:: 2 if we can't get a PID.
:: 3 if PowerShell is not present or doesn't work.
::
:LaunchPowerShellSubProcess
SET LOCALV_PID=
SET LOCALV_TIMEOUT=300
IF NOT "%~1" == "" SET LOCALV_PID=%~1
IF NOT "%~2" == "" SET LOCALV_TIMEOUT=%~2
powershell -command "$_" 2>&1 >NUL
IF NOT "!ERRORLEVEL!" == "0" EXIT /B 3
IF "!LOCALV_PID!" == "" (
FOR /F %%P IN ('powershell -command "$parentId=(Get-WmiObject Win32_Process -Filter ProcessId=$PID).ParentProcessId; write-host (Get-WmiObject Win32_Process -Filter ProcessId=$parentId).ParentProcessId;"') DO (
SET LOCALV_PID=%%P
)
)
IF "!LOCALV_PID!" == "" EXIT /B 2
START /B powershell -command "$cmdPID=$PID; Start-Job -ArgumentList $cmdPID -ScriptBlock { $ProcessActive = $true; $timeout=!LOCALV_TIMEOUT!; while((!LOCALV_TIMEOUT! -eq -1 -or $timeout -gt 0) -and $ProcessActive) { Start-Sleep -s 1; $timeout-=1; $ProcessActive = Get-Process -id !LOCALV_PID! -ErrorAction SilentlyContinue; } if ($timeout -eq 0 -or ^! $ProcessActive) { Stop-Process -Id $args; } } | Out-Null ; $npipeServer = new-object System.IO.Pipes.NamedPipeServerStream('PowerShellCon_!LOCALV_PID!', [System.IO.Pipes.PipeDirection]::In); Try { $npipeServer.WaitForConnection(); $pipeReader = new-object System.IO.StreamReader($npipeServer); while(($msg = $pipeReader.ReadLine()) -notmatch 'QUIT') { $disp='write-host '+$msg+';'; invoke-expression($disp); $npipeServer.Disconnect(); $npipeServer.WaitForConnection(); }; } Finally { $npipeServer.Dispose(); }" 2>NUL
SET /A LOCALV_TRY=20 >NUL
:LaunchPowerShellSubProcess_WaitForPipe
powershell -nop -c "& {sleep -m 50}"
SET /A LOCALV_TRY=!LOCALV_TRY! - 1 >NUL
IF NOT "!LOCALV_TRY!" == "0" cmd /C "ECHO -NoNewLine|MORE 1>\\.\pipe\PowerShellCon_!LOCALV_PID!" 2>NUL || GOTO:LaunchPowerShellSubProcess_WaitForPipe
IF "!LOCALV_TRY!" == "0" EXIT /B 1
EXIT /B 0
For windows 10, In native batch replacing %~dp0input.txt with the logs path:
::: Author T3RRY : Created 09/04/2021 : Version 1.0.1
:::
::: Purpose : Color and cursor position macro for windows 10 batch files
::: - Allows rapid display of colored output at specified screen position.
::: For more information, read the usage.
:::
::: Uses macro parameter and switch handling template.
::: - See : https://pastebin.com/gzL7AYpC
#Echo off
:# Windows Version control. Assigns flag true if system is windows 10.
Set "Win10="
Ver | Findstr /LIC:" 10." > nul && Set "Win10=true"
:# Test if virtual terminal codes enabled ; enable if false
:# removes win10 flag definition if version does not support Virtual Terminal sequences
If defined Win10 (
Reg Query HKCU\Console | %SystemRoot%\System32\findstr.exe /LIC:"VirtualTerminalLevel REG_DWORD 0x1" > nul || (
Reg Add HKCU\Console /f /v VirtualTerminalLevel /t REG_DWORD /d 1
) > Nul || Set "Win10="
)
If not defined Win10 (
Echo(Virtual terminal sequences not supported on your system
Exit /B 1
)
If "%~1" == "" (
Mode 200,150
Cls
)
(Set \n=^^^
%= \n macro newline variable. Do not modify =%)
:# assign virtual terminal control character 0x27 'escape' variable \E
For /F %%a in ( 'Echo prompt $E ^| cmd' )Do Set "\E=%%a"
:# Virtual Terminal 'VT' sequence Resource :
:# https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
::# usage: %$Cout% /Switch /Switch value
::# -----------------------------------------------------------------------------------------------------
::# Available Switches : Description:
::# -----------------------------------------------------------------------------------------------------
::# /Help : This help screen
::#
::# /S String : String to be output
::# /S String{FS} : '/' must be substituted with {FS}
::#
::# /C Integer : Declare output color using VT sequence
::# /C Integer,Integer : Chain mulitple VT color sequences
::# /C Integer;Integer : Combine multiple VT values into the one sequence
::#
::# /Y Integer : Move cursor to Line Integer [ absolute ]
::# /X Integer : Move cursor to Column Integer [ absolute ]
::# /U Integer : Move cursor Up by Integer
::# /D Integer : Move cursor Down by Integer
::# /R Integer : Move cursor Right by Integer
::# /L Integer : Move cursor Left by Integer
::#
::# /H - : Hide the cursor
::# /H + : Show the cursor
::# /Alt : Switch to alternate buffer [ main buffer is preserved ]
::# /Main : Return to main screen buffer [ alternate buffer is cleared ]
::# /K : Clears text to right of current cursor position
::# /Z Integer : Deletes Integer columns right of the cursor, shifting existing text left
::# /I Integer : Inserts whitespace into Integer columns right of Cursor, shifting text right
::# /N : Output a newline after other switches are executed.
::# -----------------------------------------------------------------------------------------------------
::#
:# Note on macro switch handling: Switches must not share a common prefix.
:# - IE:
:# - Invalid: D and DE [ switch assessment method would assign D as true if /DE used ]
:# - Valid : DA and DE
Set Switches= "help" "S" "C" "Y" "X" "U" "D" "R" "L" "H" "Alt" "Main" "K" "Z" "I" "N"
Set $Cout=For %%n in (1 2)Do if %%n==2 (%\n%
For %%G in ( %Switches% )Do set "Switch[%%~G]="%\n%
Set "leading.args=!args:*/=!"%\n%
For /F "Delims=" %%G in ("!leading.args!")Do Set "leading.args=!args:/%%G=!"%\n%
Set ^"args=!args:"=!" %\n%
Set "i.arg=0"%\n%
For %%G in (!leading.args!)Do (%\n%
Set /A "i.arg+=1"%\n%
Set "arg[!i.arg!]=%%~G"%\n%
)%\n%
For %%G in ( %Switches% )Do If not "!args:/%%~G=!" == "!args!" (%\n%
If not "!args:/%%~G: =!" == "!args!" Set "args=!args:/%%~G: =/%%~G !"%\n%
If not "!args:/%%~G =!" == "!args!" Set "switch[%%~G]=!Args:*/%%~G =!"%\n%
If not "!args:/%%~G:=!" == "!args!" Set "switch[%%~G]=!Args:*/%%~G:=!"%\n%
If not "!switch[%%~G]:*/=!" == "!switch[%%~G]!" (%\n%
Set "Trail[%%~G]=!switch[%%~G]:*/=!"%\n%
For %%v in ("!Trail[%%~G]!")Do (%\n%
Set "switch[%%~G]=!switch[%%~G]: /%%~v=!"%\n%
Set "switch[%%~G]=!switch[%%~G]:/%%~v=!"%\n%
)%\n%
Set "Trail[%%~G]="%\n%
If "!switch[%%~G]:~-1!" == " " Set "switch[%%~G]=!switch[%%~G]:~0,-1!"%\n%
If "!switch[%%~G]!" == "" Set "switch[%%~G]=true"%\n%
)%\n%
)%\n%
If "!Switch[help]!" == "true" (For /F "Tokens=1,2 Delims=#" %%Y in ('findstr /BLIC:"::#" "%~f0"')Do Echo(%%Z) ^& Timeout /T 1 /Nobreak ^> nul ^& Pause%\n%
If not "!Switch[C]!" == "" (Set "_Color_=%\E%[!Switch[C]:,=m%\E%[!m")Else Set "_Color_="%\n%
If not "!Switch[Y]!" == "" (Set "_Ypos_=%\E%[!Switch[Y]!d")Else Set "_Ypos_="%\n%
If not "!Switch[X]!" == "" (Set "_Xpos_=%\E%[!Switch[X]!G")Else Set "_Xpos_="%\n%
If not "!Switch[U]!" == "" (Set "_Yoffset_=%\E%[!Switch[U]!A")Else Set "_Yoffset_="%\n%
If not "!Switch[D]!" == "" Set "_Yoffset_=%\E%[!Switch[D]!B"%\n%
If not "!Switch[R]!" == "" (Set "_Xoffset_=%\E%[!Switch[R]!C")Else Set "_Xoffset_="%\n%
If not "!Switch[L]!" == "" Set "_Xoffset_=%\E%[!Switch[L]!D"%\n%
If "!Switch[H]!" == "-" Set "_Cursor_=%\E%[?25l"%\n%
If "!Switch[H]!" == "+" Set "_Cursor_=%\E%[?25h"%\n%
If "!Switch[Main]!" == "true" (Set "_Buffer_=%\E%[?1049l")Else Set "_Buffer_="%\n%
If "!Switch[Alt]!" == "true" Set "_Buffer_=%\E%[?1049h"%\n%
If not "!Switch[K]!" == "" (Set "_LineClear_=%\E%[K")Else Set "_LineClear_="%\n%
If not "!Switch[Z]!" == "" (Set "_Delete_=%\E%[!Switch[Z]!P")Else Set "_Delete_="%\n%
If not "!Switch[I]!" == "" (Set "_Insert_=%\E%[!Switch[I]!#")Else Set "_Insert_="%\n%
If not "!Switch[S]!" == "" (Set "_String_=!Switch[S]:{FS}=/!")Else Set "_String_="%\n%
^< nul set /P "=!_Buffer_!!_Cursor_!!_Ypos_!!_YOffset_!!_Xpos_!!_XOffset_!!_Delete_!!_Insert_!!_Color_!!_LineClear_!!_String_!%\E%[0m"%\n%
If "!Switch[N]!" == "true" Echo(%\n%
) Else Set args=
:# enable macro using Setlocal EnableExtensions EnableDelayedExpansion
CLS
If "%~1." == "/?." (
Setlocal EnableExtensions EnableDelayedExpansion
%$Cout% /help
Goto :EOF
)
For /F "usebackq Delims=" %%G in ("%~dp0input.txt")Do (
Set "Line=%%G"
Setlocal EnableExtensions EnableDelayedExpansion
If not "!Line:SUCCESS=!" == "!Line!" (
%$cout% /C 32 /N /S "!line:/={FS}!"
) Else If not "!Line:WARNING=!" == "!Line!" (
%$cout% /C 36 /N /S "!line:/={FS}!"
) Else If not "!Line:ERROR=!" == "!Line!" (
%$cout% /C 31 /N /S "!line:/={FS}!"
) Else (
%$cout% /N /S "!line:/={FS}!"
)
Endlocal
)
Goto :eof

(Batch) Is there a way to make clickable buttons?

Hi I was wondering if there is a easy way to make a clickable text buttons in a batch file. I seen people using them so i'm quite sure it is possible.
I would like to make a button to simply activate a goto test1 command.
Yes. It is.There are few options.I'll start with the first one and will edit the answer with more.
1) Using IExpress. Here's a link to example Yes/No pop-up.You can handle the result with FOR /F and decide what to do. At the beginning of the script you can set a title and question :
for /f %%a in ('iexpYNButton.bat') do set ans=%%a
if %ans% equ yes (
do something
)
2) With MSHTA - this is again Yes/No pop-up
for /f "tokens=3 delims=: " %%a in ('choose.bat') do #set ans=%%a
if %ans% equ yep (
do something
)
Here's a method that uses Carlos Aguilera's BG.exe (included) to wait for and read mouse clicks.
A number of functions and macros are included to simplify creation of custom buttons and their use. A usage example is included at the :main label at the end of the script.
#Echo off & CD /d "%~dp0"
CLS
:# Based on: https://www.dostips.com/forum/viewtopic.php?f=3&t=9222
:# example begins at 'main' label at end of file
If not exist "%TEMP%\Games_By_T3RRY\" MD "%TEMP%\Games_By_T3RRY"
If not exist "%TEMP%\Games_By_T3RRY\BG.exe" Certutil -decode "%~f0" "%TEMP%\Games_By_T3RRY\BG.exe" > nul
Set BG.exe="%TEMP%\Games_By_T3RRY\BG.exe"
Set "reg.restore=(Call )"
:# disable QuickEdit if enabled. Restored at :end label if disabled by script
reg query HKEY_CURRENT_USER\console\ /v Quickedit | findstr.exe /l "0x1" > nul && (
(Reg add HKEY_CURRENT_USER\console\ /v QuickEdit /t REG_DWORD /d 0x0 /f) > nul
Set "reg.restore=Reg add HKEY_CURRENT_USER\console\ /v QuickEdit /t REG_DWORD /d 0x1 /f"
)
For /f "tokens=4 Delims=: " %%C in ('CHCP')Do Set "active.cp=%%C"
chcp 65001 > nul
For /f %%e in ('echo prompt $E^|cmd')Do Set \E=%%e
If "!!" == "" (Echo DelayedExpansion must not be enabled before macro definitions&Pause & Exit /B 1)
:# Alt: %Buffer:#=Alt% Main: %Buffer:#=Main%
Set "Buffer=<nul set /p "=%\E%[?1049!#!""
Set "Alt=h"
Set "Main=l"
:# button sound fx. disable by undefining buttonsfx below ; prior to definition of OnCLick macro
Set "buttonsfx=On"
%BG.exe% Play "%WINDIR%\Media\Windows Feed Discovered.wav"
Set "OnClick=(Call )"
Set "OnType=(Call )"
If defined buttonsfx (
For /f "Delims=" %%G in ('Dir /b /s "%WINDIR%\SystemApps\*KbdKeyTap.wav"')Do If exist "%%~G" Set "OnClick=(Start /b "" %BG.exe% Play "%%~G")"
Set "OnType=(start /b "" %BG.exe% Play "%WINDIR%\Media\Windows Feed Discovered.wav")"
)
:# return button click coords in c{pos} variable n Y;X format
Set "GetClick=Set "Clicked="& Set "ValidClick="& for /f "tokens=1,2" %%X in ('%BG.exe% mouse')Do (Set /A "c{pos}=%%X+1"&Set "c{pos}=%%Y;!c{Pos}!")"
:# test substituted button # if click is within btn[#][coords] defines variables: Clicked [value eq string] ; ValidClick [value eq button number / undefined]; btn{State}[#] [value eq true/false]
Set "If.Button=For /f "Tokens=1,2 Delims=;" %%X in ("!c{pos}!")Do If not "!btn[#][Coords]:[%%Y;%%X]=!" == "!btn[#][Coords]!" Set "Clicked=!btn[#][string]!"& Set "ValidClick=#"& (If defined btn[#]{t} Call :Toggle #)& "
:# tests all buttons in same way as if.clicked ; exclude a button via substring modification substituting 'exc' for 'button#'
Set "qClicked=(For /l %%i in (1 1 !btns[i]!)Do If not "%%i"=="Exc" For /f "Tokens=1,2 Delims=;" %%X in ("!c{pos}!")Do If not "!btn[%%i][Coords]:[%%Y;%%X]=!" == "!btn[%%i][Coords]!" Set "Clicked=!btn[%%i][string]!"& Set "ValidClick=%%i"& %OnClick% & (If defined btn[%%i]{t} Call :Toggle %%i))& "
:# Id if button is an input bar. Requires additional Args. Optional -f switch forces input
:# Usage: %qInput% <Prompt> [-f]
Set qInput=Set "Input="^& Echo({!Clicked!}^|findstr /RC:"\<[{][ ]*[}]\>" ^> nul ^&^& Call :InputBar !ValidClick!
:# display all buttons
Set "dButtons=For /l %%i In (1 1 !btns[i]!)Do <nul Set /P "=!btn[%%i]!""
:# Undefine all buttons. Use substring modification to exclude a specific button or states from being undefined.
:# IE Preserve button 1: %clrButtons:$EXC=btn[1]%
Set "clrButtons=(For /f "tokens=1 Delims==" %%G In ('Set btn')Do Echo("%%G"|findstr /Lic:"$EXC" || Set "%%G=") 2> nul & CLS"
:# displays all selected button or input values
Set "dValues=For /l %%i in (1 1 !btns[i]!)Do if defined btn{State}[%%i] (set "value=%\E%[0;7m!btn{State}[%%i]:true=%\E%[0;32mtrue!"& Echo(%\E%[33mButton[%%i]%\E%[36m=!value:false=%\E%[0;90mfalse!%\E%[0m)"
:# menu macro for easily creating multiple buttons simultaneously
Set "CHash=Col"
set "menu=Set "m{\c}="& For %%n in (1 2)Do if %%n==2 ((If "!CHash!"=="Col" (Set "m{\c}="&Call:createmenu !Params! 2> nul )Else (Set /A "m{\c}=Col"&Call :Createmenu ^!Params^! 2> nul ))& Set "m{\c}="&Set "m{x}=2")Else Set Params="
==========
Goto :Main
==========
:# FUNCTIONS
====
:end
(%Reg.Restore%) > nul
(Title )
<nul set /p "=%\E%[?25h"
CHCP %active.cp% > nul
Endlocal
Goto :Eof
=================
:Toggle <button#>
If "!btn{State}[%~1]!"=="true" (
<nul set /P "=!btn[%~1]!"
Set "btn{State}[%~1]=false"
)Else (
<nul set /P "=!btn[%~1]:48=7;48!"
Set "btn{State}[%~1]=true"
)
Exit /b 0
:createGrid <Character> <Min> <Max> <FGcol> <BGcol> <BTNcol>
Set "Char=%~1"
For /L %%Y in (%~2 3 %~3)Do For /L %%X in (%~2 3 %~3)Do Call:CreateButton "!Char:~0,1!" %%Y %%X "%~4" "%~5" "%~6" -t
Goto :Eof
==========================================================
:createbutton <string> <y> <x> <FGcol> <BGcol> <BTNcol> -t
:# Arg Structure: 1,2,3 = Mandatory ; 4,5,6 = Optional ; -t = Optional switch. Must be Last arg if present.
:# Button Border ; Recommended font: Lucida Console
:# Codepage: 65001
:# alt 201 alt 205 alt 187 ╔═╗
:# alt 186 space alt 186 ║ ║
:# alt 200 alt 205 alt 188 ╚═╝
Set "l[Y]=!btn[Y]!"
If not "%~2"=="!btn[Y]!" Set /A "btn[Y]=%~2+3"
If "%~3" == "" Exit /b 1
Set /a "btns[i]+=1+0"
Set "btn[%btns[i]%][p]=%~2;%~3"
Set "btn[%btns[i]%][string]=%~1"
If /I "%~4" == "-t" (set "btn[BG]=%\E%[48;2;230;230;200m")Else (If "%~4" == "" (set "btn[BG]=%\E%[48;2;230;230;200m")Else set "btn[BG]=%\E%[38;2;%~4m")
If /I "%~5" == "-t" (set "btn[FG]=%\E%[38;2;;;m")Else (If "%~5" == "" (set "btn[FG]=%\E%[38;2;;;m")Else set "btn[FG]=%\E%[48;2;%~5m")
If /I "%~6" == "-t" (set "btn[Col]=%\E%[90m")Else (If "%~6" == "" (set "btn[Col]=%\E%[90m")Else set "btn[Col]=%\E%[%~6m")
:# defines variable identifying button as toggle button; used by %If.Button% and %qClicked% macros
Echo("%*"|findstr /lic:"-t" > nul && Set "btn[%btns[i]%]{t}=true" || Set "btn[%btns[i]%]{t}="
:# Constrain button creation to console dimensions
For /f "Tokens=1,2 Delims=: " %%G in ('Mode^|findstr /lic:"Columns" /lic:"Lines"')Do (
Set /A "%%G=%%H"
If /I "%%G"=="Columns" ( Set /A "%%G[max]=%%H+%~3+2" )Else Set /A "%%G[max]=%%H"
)
Set "len="& set "s=#%~1" & ( for %%P in (8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do ( if "!s:~%%P,1!" NEQ "" ( set /a "len+=%%P" & set "s=!s:~%%P!" ))) & set /a "btn[%btns[i]%][Len]=len" 2>nul
If !len! GTR !Columns[Max]! (
Echo(Button length exceeds display width. Button width must be LSS than console Columns
Pause
Exit
)
If %~2 GEQ !Lines[Max]! (
Echo(Button height exceeds display height. Button height must be LSS than console Lines
Pause
Exit
)
:# define button click coords and button Upper / lower border display values
:# - border is not defined as clickable.
Set /A "btn{Xmin}=%3+1", "btn{Xmax}=%3+len", "l[X]=btn{Xmax}+2"
Set "btn[%btns[i]%][Len]=" & Set "btn[%btns[i]%][S]=" & Set "btn[%btns[i]%][coords]="
For /l %%i in (!btn{Xmin}! 1 !btn{Xmax}!)Do (
Set /A "btn[%btns[i]%][Len]=%%i-3", "Xoffset=%%i-1"
Set "btn[%btns[i]%][coords]=!btn[%btns[i]%][coords]![%2;!Xoffset!]"
Set "btn[%btns[i]%][Bar]=!btn[%btns[i]%][Bar]!═"
Set "btn[%btns[i]%][S]=!btn[%btns[i]%][S]! "
)
:# define toggle state variable
If defined btn[%btns[i]%]{t} Set "btn{State}[%btns[i]%]=false"
:# Button Graphic. Toggle is effected by substituting Background color VT code 48 with 7;48 to invert button text color.
Set "btn[%btns[i]%]=%\E%[%2;%3H%Btn[col]%%\E%7║%\E%8%\E%A╔!btn[%btns[i]%][Bar]!╗%\E%8%\E%B╚!btn[%btns[i]%][Bar]!╝%\E%8%\E%C%\E%[0m!btn[FG]!!btn[BG]!!btn[%btns[i]%][String]!%\E%[0m%btn[col]%║%\E%[0m%\E%[2E%\E%7"
Set "btn[%btns[i]%][t]=%\E%[0m!btn[FG]!!btn[BG]!!btn[%btns[i]%][String]!%\E%[0m%btn[col]%║%\E%[0m%\E%[K"
Exit /b 0
==========================================
:createMenu <"list" "of" "button strings">
:# Associated Macro: %Menu%
:# - Uses default values for button color schemes m{fg} m{bg} and m{olc}
:# - Define the value of those variables prior to calling :createMenu
:# to the desired color scheme if you wish to override default values.
:# - Defaults to Row 3 [button base] unless m{yo} defined with value to overide default
:# - Defaults to Column 1 if m{x} is not defined with a column value.
:# - m{\c} overides m{x} to value of the new column. %Menu% macro resets m{x} to 2 as default x pos after use.
:# - Button count is reset unless m{\c} is defined using substring modification of
:# - %menu% macro: Ie: %Menu:Col=15% list of options
:# - Int X pos value for new column
:# ! Note: Columns are not automatically padded for options of different lengths.
:# - Use white space in options list to pad options for buttons of equal size.
:# IE: %Menu% " short button " "A Very Much Longer Button"
If not defined m{\c} (
cls
Set "btns[i]="
Set "display.menu=Call Echo("
Set "b{i}=0"
)
If not defined m{yo} (Set "m{y}=3")Else Set /A "m{y}=m{yo}"
If not defined m{fg} (Set "m{fg}=;160;200")
If not defined m{bg} (Set "m{bg}=150;;150")
If not defined m{olc} (Set "m{olc}=33")
If defined m{\c} (Set "m{x}=!m{\c}!")
If not defined m{x} (Set "m{x}=2")
For %%v in (%*)Do (
Call :CreateButton "%%~v" !m{y}! !m{x}! "!m{fg}!" "!m{bg}!" !m{olc}! -t 2> nul
Set "display.menu=!display.menu!%%button[!b{i}!]%%"
Set /a "m{y}+=3", "b{i}+=1"
)
%display.menu%
Exit /b 0
=================================
:InputBar <button#> <Prompt> [-f]
:# Force Input via switch -f
:# Constrains display of input to the dimensions of the inout bar. Longer input may still be entered; input display
:# is limited to the last n characters, where 'n' is the length of the input bar
set "input="
Set /A "CurrIn=0", "MaxIn=!btn[%1][Len]!"
<nul Set /P "=%\E%[!btn[%1][p]!H%\E%C%\E%7"
For /f "delims=" %%v in ('Set /A "MaxIn+1"')Do <nul Set /P "=%\E%[%%vX%\E%8%\E%[?25h%\E%[?12h"
%BG.exe% cursor 100
:entryloop
Title %~2
%BG.exe% kbd
Set "key=!k[%Errorlevel%]!"
If not "!Key!" == "" (
If not "!Key!"=="Enter" (
If "!Key!"=="Backspace" (
If not !CurrIn!==0 (
%OnType%
Set "Input=!Input:~0,-1!"
Set /A "CurrIn-=1"
<nul set /p "=%\E%D %\E%D"
)Else Start /b "" %BG.exe% play "%WINDIR%\Media\Windows critical stop.wav"
)Else (
If not "!Key!"=="?" (
Echo("!Key!"|findstr.exe /lic:"home" /lic:"end" /lic:"pageup" /lic:"pagedown" /lic:"space" /lic:"tab" /lic:"left" /lic:"right" /lic:"up" /lic:"down" /lic:"delete" /lic:"escape" > nul && (
If /I "!Key!"=="escape" (Start /b "" %BG.exe% play "%WINDIR%\Media\Windows critical stop.wav")
If /I "!Key!"=="delete" (
Start /b "" %BG.exe% play "%WINDIR%\Media\recycle.wav"
Goto :InputBar
)
If /I "!Key!"=="Space" (
Set "Input=!Input! "
Set /A "CurrIn+=1"
)
) || (
Set "Input=!Input!!Key!"
Set /A "CurrIn+=1"
)
)Else (%= ? Cannot be Echoed to findstr; results in help output. =%
Set "Input=!Input!?"
Set /A "CurrIn+=1"
)
%OnType%
)
If not "!input!"=="" <nul set /p "=%\E%8!Input:~-%MaxIn%!"
Goto :entryloop
)
)
:# Key is Enter. Test -f force input switch; force input if true
If /I "%~3" == "-f" If "!input!" == "" (
Start /b "" %BG.exe% play "%WINDIR%\Media\Windows Error.wav"
Goto :InputBar
)
<nul Set /P "=%\E%[?25l%\E%8%\E%[K!btn[%1][t]:255;255;255=180;180;250!"
%BG.exe% play "%WINDIR%\Media\Windows Navigation Start.wav"
<nul Set /P "=%\E%8!btn[%1][t]!%\E%[?25l%\E%[?12l"
Set "btn{State}[%1]="
If not "!Input!"=="" Set "btn{State}[%1]=!Input!"
:# 255 char title length limit
If "!Input:~0,237!"=="" (%= Double Quote string at output to prevent code insertion =%
Title You Entered: "!Input!"
)Else If not "!Input!"=="" (
Title You Entered: "!Input:~0,239!"
)Else Title ^^! No input entered.
Exit /B 0
========
:DefKeys
Set "k[8]=Backspace"
(Set LF=^
%= empty lines above are required. =%)
rem For /l %%i in (9)Do For /F eol^=^%LF%%LF%^ delims^= %%A in ('forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(0x09"') do Set "k[9]=%%A"
Set "k[13]=Enter"& Set "k[27]=Escape"& Set "k[32]=Space"& Set "k[33]=^!"& Set ^"k[34]=""
set "i=35"
For %%k in (
"#" "$" "%%" "&" "'" "(" ")" "ASsub" "+" "," "-" "." "/"^
"0" "1" "2" "3" "4" "5" "6" "7" "8" "9"^
":" ";" "<" "=" ">" "QMsub" "#"^
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z^
"[" "\" "]" "^^" "_" "`"^
a b c d e f g h i j k l m n o p q r s t u v w x y z^
)Do (
Set "k[!i!]=%%~k"
Set /A "i+=1"
)
Set "k[42]=*"& Set "k[63]=?"& Set "k[123]={"& Set "k[124]=|"& Set "k[125]=}"
Set "k[126]=~"& Set "k[339]=Delete"& Set "k[327]=Home"& Set "k[328]=Up"
Set "k[329]=PageUp"& Set "k[331]=Left"& Set "k[333]=Right"& Set "k[335]=End"
Set "k[336]=Down"& Set "k[337]=PageDown"
Exit /b 0
:# REQUIRED UTILITY
===============
/* BG.exe V 3.9
https://github.com/carlos-montiers/consolesoft-mirror/blob/master/bg/README.md
Copyright (C) 2010-2018 Carlos Montiers Aguilera
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Carlos Montiers Aguilera
cmontiers#gmail.com
*/
-----BEGIN CERTIFICATE-----
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v
dCBiZSBydW4gaW4gRE9TIG1vZGUu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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
-----END CERTIFICATE-----
=================
:Main script body
Setlocal EnableDelayedExpansion
Call :DefKeys
:# USAGE EXAMPLES // Your script below
%BG.exe% Font 9
:# buttons containing only whitespace in their text string are identified by qInput macro as Input bars
:# using findstr regex.
Call :createButton " " 2 2 "0;0;0" "255;255;255" "36" -t
Set /A "m{yo}=5", "m{\C}=2" %= define initial Y;X values of menu column =%
%Menu:Col=2% "Option 1" "Option 2" "Option 3"
%Menu:Col=l[X]% "Option 4" "Option 5" "Option 6"
%Menu:Col=l[X]% "Option 7" "Option 8" "Option 9"
Call :createButton "Click Me" 14 2 -t
Call :createButton "{ Or Me }" !l[Y]! !l[X]! -t
Call :createButton "Exit" 17 2 "200;;" "155;155;255" "48;2;60;;"
Call :createButton "Reset" 17 !l[X]! "200;;" "155;155;255" "48;2;;;100"
Call :createButton "Show Values" 17 !l[X]! "200;;" "155;155;255" "48;2;;90;"
<nul set /p "=%\E%[?25l"
:refresh
%dButtons%
:loop
%GetClick%
%qClicked% If defined ValidClick (
Title Clicked Button !ValidClick! : "!Clicked: =!"
If "!Clicked!"=="Exit" (
<nul Set /P "=%\E%[!btn[Y]!d%\E%[G"
Goto :End
)
If "!Clicked!"=="Reset" (
Endlocal
Goto :main
)
If "!Clicked!"=="Show Values" (
%Buffer:#=Alt%
%dValues%
Pause
%Buffer:#=Main%
Goto :loop
)
%qInput% "Enter something:" -f
)Else Title Clicked: !C{Pos}!
Goto :loop

Changing caret/cursor position

today I'm here to give you all a new challenge!
Just joking: my problem is the caret of the Command Prompt. [The "entire" story is in the bottom"]
Short story long, I have to move the caret positions to ECHO a new line in the same position.
That's because I have to print only few strings [about three lines]; making a CLS every time it blinks because of the speed of the execution.
I tried some things, also using the <NUL SET /P "=InsertHereString", but there's always the problem of what I already ECHOed that doesn't disappear!
So here's my request: There's a method to move that blinking bunch of pixel allowing to write a string starting from a certain point of the CMD?
BOTTOM:
The "entire" story is that I made a sort of installer in batch, copying and linking some applications from a removable drive.
Now, I also made a status bar saying in percentage what is done.
Under the status bar I want to show what actually the program is doing, but when there are [for example] a lot of file in a directory to link or copy, it makes a list instead of erasing the previous thing, so at the moment I'm simply ECHOing a " - Done!" or a" - Failed!" string next to the main string.
I asked for that because in another language [C++] I found a method that I used to make a PacMan simulation.
It consists in a method that want an X and an Y variable that identify the caret position in a Cartesian plane where the (0,0) position is the up-left corner of the Command Prompt.
Thanks for your time!
BG v2.5 (unicode)
http://batch.xoo.it/t2238-BG-exe-Utility-for-Batch-Games.htm
BG.EXE is a tool for print text color in cmd.exe. It accepts regular
expressions for print ascii characters. It also have useful functions.
Locate row column
::locate the position of cursor in row and column specified, zero index based.
Call it: bg Locate 0 0 and the cursor jumps there.
Or
CursorPos.exe
http://www.dostips.com/forum/viewtopic.php?f=3&t=3428
Get or set cursor position.
CursorPos [[±]col [±]row]
If no parameter is given, return current cursor position as
col+(row<<16) in ERRORLEVEL.
If any coordinate have sign, the position given is relative to the
current one.
If cursor is moved, the Ascii code of the character at new position is
returned in ERRORLEVEL.
It takes a little bit to get used to using cursorpos. Here's a proof of concept. Not sure whether this is similar to what you had in mind, but I think the trickery you have in mind is possible. Anything is possible given enough beer.
Save this as pacman.bat and run it. The result is spectacular :P (Moreso if your console is using a truetype font.)
#echo off
setlocal enabledelayedexpansion
Rem cursorpos and colorshow created by Antonio Perez Ayala
Rem http://www.dostips.com/forum/viewtopic.php?f=3&t=3428
call :heredoc cursorpos >cursorpos.hex && goto endCursorpos
4D5A900003[3]04[3]FFFF[2]B8[7]40[35]B0[3]0E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F74
2062652072756E20696E20444F53206D6F64652E0D0D0A24[7]55B5B8FD11D4D6AE11D4D6AE11D4D6AE9FCBC5AE18D4D6AEED
F4C4AE13D4D6AE5269636811D4D6AE[8]5045[2]4C010200EB84E24F[8]E0000F010B01050C0002[3]02[7]10[3]10[3]20[4]40[2]10
[3]02[2]04[7]04[8]30[3]02[6]03[5]10[2]10[4]10[2]10[6]10[11]1C20[2]28[84]20[2]1C[27]2E74657874[3]4201[3]10[3]02[3]02[14]20[2]60
2E7264617461[2]F6[4]20[3]02[3]04[14]40[2]40[8]E806[3]50E81301[2]558BEC83C4E06AF5E81201[2]8945FC8D45E650FF75FCE8
FD[3]668B45EC668945E4E8BC[3]E8DB[3]803E0075058B45EAEB5C803E3D750646E8C6[3]668B4DEAE84A[3]8945EAE8B5[3]803E
007418803E2C750646E8A5[3]668B4DE4E829[3]668945EC8B5DEA53FF75FCE8AE[3]8D45E650536A018D45E350FF75FCE895[3]0F
B645E3C9C333C032DB33D28A164680FA2B740880FA2D750980CB0280CB018A164680FA30720F80FA39770A80EA306BC00A03
C2EBE9F6C301740BF6C302740366F7D86603C14EC3CCCCCCCCCCCCCCCCCCCCCCCCCCE847[3]8BF08A06463C2275098A06463C
2275F9EB0C8A06463C20740484C075F54EC38A06463C2074F94EC3CCFF2514204000FF2500204000FF2504204000FF250820
4000FF250C204000FF25102040[191]6E20[2]8C20[2]9C20[2]BA20[2]D620[2]6020[6]4420[10]E820[3]20[22]6E20[2]8C20[2]9C20[2]BA
20[2]D620[2]6020[6]9B004578697450726F6365737300F500476574436F6E736F6C6553637265656E427566666572496E666F
[2]6A0147657453746448616E646C65[2]380252656164436F6E736F6C654F757470757443686172616374657241006D025365
74436F6E736F6C65437572736F72506F736974696F6E[2]E600476574436F6D6D616E644C696E6541006B65726E656C33322E
646C6C[268]
:endCursorpos
call :heredoc colorshow >colorshow.hex && goto endShow
4D5A900003[3]04[3]FFFF[2]B8[7]40[35]B8[3]0E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F74
2062652072756E20696E20444F53206D6F64652E0D0D0A24[7]5549FA721128942111289421112894219F3787211A289421ED
088621132894215269636811289421[16]5045[2]4C0103001DDBEB50[8]E0000F010B01050C0006[3]04[7]10[3]10[3]20[4]40[2]10
[3]02[2]04[7]04[8]40[3]04[6]03[5]10[2]10[4]10[2]10[6]10[11]2420[2]28[84]20[2]24[27]2E74657874[3]DE04[3]10[3]06[3]04[14]20[2]60
2E7264617461[2]3201[3]20[3]02[3]0A[14]40[2]402E64617461[3]20[4]30[3]02[3]0C[14]40[2]C0[472]E806[3]50E8A304[2]558BEC81C4
E8DFFFFFFC6AF5E8A404[2]8945FC6800304000FF75FCE88804[2]8B1D043040008D85E8DFFFFF50536A018D45FA50FF75FCE8
7E04[2]668B45FA66A316304000D41086C4D510668945F88DBDF8DFFFFF89BDF4DFFFFFE81304[2]E83204[2]8A064684C00F84
4803[2]3C2F0F858C[3]2BBDF4DFFFFF74186A008D85E8DFFFFF5057FFB5F4DFFFFFFF75FCE85F03[2]8BBDF4DFFFFF8A064684
C00F840F03[2]3C20750C668B45FA66A316304000EBA73C2F750C668B45F866A316304000EB972C303C0976082C073C0F7602
2C208A264684E40F84D602[2]80FC20741286C42C303C0976082C073C0F76022C20D51066A316304000E95CFFFFFF3C227520
8A064684C00F84A502[2]3C227405880747EBEC8A06463C2274F4E938FFFFFF3C300F82C6[3]3C390F87BE[3]E8A102[2]3C2A74
083C5874043C7875278ADC468A06463C300F826102[2]3C390F875902[2]E87A02[2]0FB6CC8AC3F3AAE9F0FEFFFF80FC207379
80FC09751F8B0D0430400003CF2B8DF4DFFFFF83E10783E908F7D9B020F3AAE9C7FEFFFF2BBDF4DFFFFF741A506A008D85E8
DFFFFF5057FFB5F4DFFFFFFF75FCE83D02[2]588BBDF4DFFFFF88276A008D85E8DFFFFF506A01FFB5F4DFFFFFFF75FCE8E302
[2]6800304000FF75FCE8BE02[2]E972FEFFFF882747E96AFEFFFF2BBDF4DFFFFF74186A008D85E8DFFFFF5057FFB5F4DFFFFF
FF75FCE8E101[2]8BFE4F33DB889DF2DFFFFF8A063C3A74118885F3DFFFFF3C20746084C0745C46EBE9889DF2DFFFFFC6060046
8A06463C2D7509C685F2DFFFFF02EB0B3C2B750AC685F2DFFFFF018A06463C300F827001[2]3C390F876801[2]E86901[2]8885
F3DFFFFF3C20740884C00F855101[2]84E40F841001[2]8ADCC60600680020[2]8D85F8DFFFFF5057E80702[2]85C00F84F1[3]85
DB0F84CF[3]3BC30F84C7[3]7C2D80BDF2DFFFFF00741DF685F2DFFFFF01750A2BC30185F4DFFFFFEB0A2BC3D1E80185F4DFFF
FF8BC3E998[3]2BD88BBDF4DFFFFF03F889BDECDFFFFF50B0208BCBF3AA80BDF2DFFFFF007443F685F2DFFFFF02741C6A018D
85E8DFFFFF5053FFB5ECDFFFFFFF75FCE8C9[3]33DBEB1E8BFBD1EF2BDF6A018D85E8DFFFFF5057FFB5ECDFFFFFFF75FCE8A7
[3]588BF86A018D85E8DFFFFF5057FFB5F4DFFFFFFF75FCE88C[3]6A028D85E8DFFFFF5053FFB5ECDFFFFFFF75FCE874[3]EB1A
8BF86A008D85E8DFFFFF5057FFB5F4DFFFFFFF75FCE858[3]8A85F3DFFFFF88068DBDF8DFFFFF89BDF4DFFFFFE9A8FCFFFF2B
BDF4DFFFFF74186A008D85E8DFFFFF5057FFB5F4DFFFFFFF75FCE81F[3]0FB745FAC9C3240F8AE08A06463C30720C3C397708
2C30D50A8AE0EBED4EC3558BEC6A00FF7514FF7510FF750CFF7508E8B2[3]8B4D1066837D180172137708010D18304000EB46
030D18304000894D10578B7D0C66A116304000F366AB8B0D04304000FF751451FF7510FF750CFF7508E876[3]5F6800304000FF
7508E84A[3]C705183040[5]C9C21400CCCCCCCCCCCCCCCCE853[3]8BF08A06463C2275098A06463C2275F9EB0C8A06463C2074
0484C075F54EC38A06463C2074F94EC3CCFF2500204000FF2504204000FF2508204000FF250C204000FF2510204000FF2514
204000FF2518204000FF251C2040[291]7020[2]7E20[2]9C20[2]B620[2]C620[2]E420[2]F420[2]1221[6]4C20[10]2421[3]20[22]7020[2]7E
20[2]9C20[2]B620[2]C620[2]E420[2]F420[2]1221[6]9B004578697450726F6365737300F500476574436F6E736F6C6553637265
656E427566666572496E666F[2]1301476574456E7669726F6E6D656E745661726961626C6541006A0147657453746448616E
646C65[2]370252656164436F6E736F6C654F7574707574417474726962757465[2]EE025772697465436F6E736F6C654100F2
025772697465436F6E736F6C654F757470757441747472696275746500E600476574436F6D6D616E644C696E6541006B6572
6E656C33322E646C6C[720]
:endShow
call :heredoc hexchar >hexchar.vbs && goto endHexchar
Rem Hex digits to Ascii Characters conversion
Rem Antonio Perez Ayala - Apr/14/2012
Dim line,index,count
line = WScript.StdIn.ReadLine()
While line <> ""
index = 1
While index < len(line)
If Mid(line,index,1) = "[" Then
index = index+1
count = 0
While Mid(line,index+count,1) <> "]"
count = count+1
WEnd
For i=1 To Int(Mid(line,index,count))
WScript.StdOut.Write Chr(0)
Next
index = index+count+1
Else
WScript.StdOut.Write Chr(CByte("&H"&Mid(line,index,2)))
index = index+2
End If
WEnd
line = WScript.StdIn.ReadLine()
WEnd
:endHexchar
:: Create cursorpos.exe and colorshow.exe
for %%I in (cursorpos colorshow) do (
cscript /nologo /B /E:VBS HexChar.vbs < "%%I.hex" > "%%I.exe"
del %%I.hex
)
del hexchar.vbs
:: ---------------------------------------------------
:: Supporting applications all created. Now use them.
:: ---------------------------------------------------
call :DefineColorCodes
set /P I="Waiting... "<NUL
cursorpos
call :GetCoords Cols Lines
for /l %%A in (1, 1, 3) do (
colorshow /%Black% " " /%Yellow%%Black% "(<" /%White% " o o o o o"
for /l %%I in (2, 1, 15) do (
call :sleep 100
set /a pos=%Cols% + %%I
cursorpos !pos! %Lines%
set /a e=%%I %% 2
if #!e!==#1 (
colorshow /%Black% " " /%Yellow%%Black% "(<"
) else colorshow /%Black% " " /%Yellow%%Black% "(-"
)
for /l %%I in (15, -1, 2) do (
call :sleep 100
set /a pos=%Cols% + %%I
cursorpos !pos! %Lines%
set /a e=%%I %% 2
if #!e!==#1 (
colorshow /%Yellow%%Black% ">)" /%Black% " "
) else colorshow /%Yellow%%Black% "-)" /%Black% " "
)
cursorpos=%Cols%,%Lines%
)
:: ---------------------------------------------------
:: End of main script
:: ---------------------------------------------------
echo Done.
del cursorpos.exe colorshow.exe sleep.vbs
goto :EOF
:: ---------------------------------------------------
:: Subroutines
:: ---------------------------------------------------
:GetCoords Cols= Lines=
set /A "%1=%errorlevel%&0xFFFF, %2=(%errorlevel%>>16)&0xFFFF"
exit /B
:DefineColorCodes
set HexDigit=0123456789ABCDEF
set c=-1
for %%c in ( Black Blue Green Aqua Red Purple Brown White
Grey LBlue LGreen LAqua LRed LPurple Yellow BWhite ) do (
set /A c+=1
for %%C in (!c!) do set %%c=!HexDigit:~%%C,1!
)
exit /B
:sleep <ms>
if not exist sleep.vbs (echo Wscript.Sleep^(Wscript.Arguments^(0^)^)>sleep.vbs)
cscript /nologo sleep.vbs %1
goto :EOF
:heredoc <uniqueIDX>
setlocal enabledelayedexpansion
set go=
for /f "delims=" %%A in ('findstr /n "^" "%~f0"') do (
set "line=%%A" && set "line=!line:*:=!"
if defined go (if #!line:~1!==#!go::=! (goto :EOF) else echo(!line!)
if "!line:~0,13!"=="call :heredoc" (
for /f "tokens=3 delims=>^ " %%i in ("!line!") do (
if #%%i==#%1 (
for /f "tokens=2 delims=&" %%I in ("!line!") do (
for /f "tokens=2" %%x in ("%%I") do set "go=%%x"
)
)
)
)
)
goto :EOF
ANSICON provides ANSI escape sequences for Windows console programs. It provides much the same functionality as ANSI.SYS does for MS-DOS.
https://github.com/adoxa/ansicon

How do I get brown text in a batch file?

I am wondering if anyone knows how to change the color of text in a batch file to brown so I can use it to make dirt in my batch games.
You can use the command color followed by one of the values shown in the screenshot:
Brown is not available as a color in the command-prompt so you have to chose an alternative color like 8 for gray.
To only color specific parts of your text you need to use API-function, which is not possible within batch-scripts. However, have a look a this tool which will provide a way to work around this limitation
Although I published my method to show color characters in Batch files three years ago, I must admit that is not easy to download the .exe auxiliary programs. The Batch file below create ColorShow.exe auxiliary program and show a brief description of its use, so you don't need to mess with the hex-to-bin conversion:
#if (#CodeSection == #Batch) #then
#echo off
rem Create ColorShow.exe auxiliary program and show its usage
rem Antonio Perez Ayala
echo Show characters in color from Ascii codes, string literals and Batch variables.
echo/
echo ColorShow /bf code[*times] ^| "literal" ^| variable[:[+^|-]wide] ...
echo/
echo /bf Specify a color attribute (see COLOR /? for more info)
echo ^<code^>, ^<times^> and ^<wide^> must be decimal numbers up to 255 each
echo/
echo ^<times^> repeat the previous Ascii ^<code^> character that number of times;
echo an X-letter may be used instead of the asterisk: codeXtimes
echo/
echo ^<wide^> define a field to show the variable value: justified at left, or
echo justified at rigth if wide have minus sign, or centered if wide have plus sign.
echo/
echo Color attributes may be inserted at any place in the show parameters, setting
echo the color of following parameters. If the first show parameter has not a
echo previous attribute, the color of initial cursor position is used.
echo/
echo Use / alone to indicate the color of initial cursor position, use // to
echo indicate the initial color attribute in reverse video.
echo/
echo At end, the original attribute of initial cursor position is returned in
echo ERRORLEVEL as a *decimal* value.
if not exist ColorShow.exe call :ExtractBinaryFile ColorShow.exe
goto :EOF
rem Extract Binary File from hexadecimal digits placed in a "resource" in this .bat file
:ExtractBinaryFile filename.ext
setlocal EnableDelayedExpansion
set "start="
set "end="
for /F "tokens=1,3 delims=:=>" %%a in ('findstr /N /B "</*resource" "%~F0"') do (
if not defined start (
if "%%~b" equ "%~1" set start=%%a
) else if not defined end set end=%%a
)
(for /F "skip=%start% tokens=1* delims=:" %%a in ('findstr /N "^" "%~F0"') do (
if "%%a" == "%end%" goto decodeHexFile
echo %%b
)) > "%~1.hex"
:decodeHexFile
Cscript //nologo //E:JScript "%~F0" "%~1" < "%~1.hex"
del "%~1.hex"
exit /B
<resource id="ColorShow.exe">
4D5A900003[3]04[3]FFFF[2]B8[7]40[35]B8[3]0E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F74
2062652072756E20696E20444F53206D6F64652E0D0D0A24[7]5549FA721128942111289421112894219F3787211A289421ED
088621132894215269636811289421[16]5045[2]4C0103001DDBEB50[8]E0000F010B01050C0006[3]04[7]10[3]10[3]20[4]40[2]10
[3]02[2]04[7]04[8]40[3]04[6]03[5]10[2]10[4]10[2]10[6]10[11]2420[2]28[84]20[2]24[27]2E74657874[3]DE04[3]10[3]06[3]04[14]20[2]60
2E7264617461[2]3201[3]20[3]02[3]0A[14]40[2]402E64617461[3]20[4]30[3]02[3]0C[14]40[2]C0[472]E806[3]50E8A304[2]558BEC81C4
E8DFFFFFFC6AF5E8A404[2]8945FC6800304000FF75FCE88804[2]8B1D043040008D85E8DFFFFF50536A018D45FA50FF75FCE8
7E04[2]668B45FA66A316304000D41086C4D510668945F88DBDF8DFFFFF89BDF4DFFFFFE81304[2]E83204[2]8A064684C00F84
4803[2]3C2F0F858C[3]2BBDF4DFFFFF74186A008D85E8DFFFFF5057FFB5F4DFFFFFFF75FCE85F03[2]8BBDF4DFFFFF8A064684
C00F840F03[2]3C20750C668B45FA66A316304000EBA73C2F750C668B45F866A316304000EB972C303C0976082C073C0F7602
2C208A264684E40F84D602[2]80FC20741286C42C303C0976082C073C0F76022C20D51066A316304000E95CFFFFFF3C227520
8A064684C00F84A502[2]3C227405880747EBEC8A06463C2274F4E938FFFFFF3C300F82C6[3]3C390F87BE[3]E8A102[2]3C2A74
083C5874043C7875278ADC468A06463C300F826102[2]3C390F875902[2]E87A02[2]0FB6CC8AC3F3AAE9F0FEFFFF80FC207379
80FC09751F8B0D0430400003CF2B8DF4DFFFFF83E10783E908F7D9B020F3AAE9C7FEFFFF2BBDF4DFFFFF741A506A008D85E8
DFFFFF5057FFB5F4DFFFFFFF75FCE83D02[2]588BBDF4DFFFFF88276A008D85E8DFFFFF506A01FFB5F4DFFFFFFF75FCE8E302
[2]6800304000FF75FCE8BE02[2]E972FEFFFF882747E96AFEFFFF2BBDF4DFFFFF74186A008D85E8DFFFFF5057FFB5F4DFFFFF
FF75FCE8E101[2]8BFE4F33DB889DF2DFFFFF8A063C3A74118885F3DFFFFF3C20746084C0745C46EBE9889DF2DFFFFFC6060046
8A06463C2D7509C685F2DFFFFF02EB0B3C2B750AC685F2DFFFFF018A06463C300F827001[2]3C390F876801[2]E86901[2]8885
F3DFFFFF3C20740884C00F855101[2]84E40F841001[2]8ADCC60600680020[2]8D85F8DFFFFF5057E80702[2]85C00F84F1[3]85
DB0F84CF[3]3BC30F84C7[3]7C2D80BDF2DFFFFF00741DF685F2DFFFFF01750A2BC30185F4DFFFFFEB0A2BC3D1E80185F4DFFF
FF8BC3E998[3]2BD88BBDF4DFFFFF03F889BDECDFFFFF50B0208BCBF3AA80BDF2DFFFFF007443F685F2DFFFFF02741C6A018D
85E8DFFFFF5053FFB5ECDFFFFFFF75FCE8C9[3]33DBEB1E8BFBD1EF2BDF6A018D85E8DFFFFF5057FFB5ECDFFFFFFF75FCE8A7
[3]588BF86A018D85E8DFFFFF5057FFB5F4DFFFFFFF75FCE88C[3]6A028D85E8DFFFFF5053FFB5ECDFFFFFFF75FCE874[3]EB1A
8BF86A008D85E8DFFFFF5057FFB5F4DFFFFFFF75FCE858[3]8A85F3DFFFFF88068DBDF8DFFFFF89BDF4DFFFFFE9A8FCFFFF2B
BDF4DFFFFF74186A008D85E8DFFFFF5057FFB5F4DFFFFFFF75FCE81F[3]0FB745FAC9C3240F8AE08A06463C30720C3C397708
2C30D50A8AE0EBED4EC3558BEC6A00FF7514FF7510FF750CFF7508E8B2[3]8B4D1066837D180172137708010D18304000EB46
030D18304000894D10578B7D0C66A116304000F366AB8B0D04304000FF751451FF7510FF750CFF7508E876[3]5F6800304000FF
7508E84A[3]C705183040[5]C9C21400CCCCCCCCCCCCCCCCE853[3]8BF08A06463C2275098A06463C2275F9EB0C8A06463C2074
0484C075F54EC38A06463C2074F94EC3CCFF2500204000FF2504204000FF2508204000FF250C204000FF2510204000FF2514
204000FF2518204000FF251C2040[291]7020[2]7E20[2]9C20[2]B620[2]C620[2]E420[2]F420[2]1221[6]4C20[10]2421[3]20[22]7020[2]7E
20[2]9C20[2]B620[2]C620[2]E420[2]F420[2]1221[6]9B004578697450726F6365737300F500476574436F6E736F6C6553637265
656E427566666572496E666F[2]1301476574456E7669726F6E6D656E745661726961626C6541006A0147657453746448616E
646C65[2]370252656164436F6E736F6C654F7574707574417474726962757465[2]EE025772697465436F6E736F6C654100F2
025772697465436F6E736F6C654F757470757441747472696275746500E600476574436F6D6D616E644C696E6541006B6572
6E656C33322E646C6C[720]
</resource>
#end
// Convert Ascii hexadecimal digits from Stdin to a binary string
var count, output = "";
while ( !WScript.Stdin.AtEndOfStream ) {
var input = WScript.Stdin.ReadLine();
for ( var index = 0; index < input.length; ) {
if ( input.charAt(index) == '[' ) {
for ( count = ++index; input.charAt(index) != ']' ; index++ ) ;
count = parseInt(input.slice(count,index++));
for ( var i = 1; i <= count; i++ ) output += String.fromCharCode(0);
} else {
output += String.fromCharCode(parseInt(input.substr(index,2),16));
index += 2;
}
}
}
// Write the binary string to the output file
var ado = WScript.CreateObject("ADODB.Stream");
ado.Type = 2; // adTypeText = 2
ado.CharSet = "iso-8859-1"; // right code page for output (no adjustments)
ado.Open();
ado.WriteText(output);
ado.SaveToFile(WScript.Arguments(0),2); // adSaveCreateOverWrite = 2
ado.Close();
This is a small example program on ColorShow.exe usage:
#echo off
setlocal EnableDelayedExpansion
set colors=0 1 2 3 4 5 6 7 8 9 A B C D E F
for %%i in (%colors%) do (
set "line="
for %%j in (%colors%) do set line=!line! /%%i%%j " %%i%%j "
ColorShow !line! 13 10
)
The output:
Windows console does not have brown color but you can try to emulate it with ascii symbols 176,177(seems to be the best option in this case) and 178 for combining foreground and background colors.Though you can use the color function by carlos it will be too slow.I would recommend the coloroutput.bat utility which after the initial compilation will be comparatively fast:
colorout.bat -s ▓▒░ -f 4 -b 14
or (closer to brown)
colorout.bat -s ▓▒░ -f 2 -b 12
the output will be something like!
or
You can try different combinations (to see all colors try with colorout.bat -help )
Have on mind that code page (can be seen with CHCP command) could corrupt the results.Mine is 437

Resources