Important to note that to change the color individually per line, you need some helper program.
The rest is basically that:
//salvar como cping.bat ou coisa do tipo
//uso: cping <IP>
@ECHO off
:top
PING -n 1 %1% | find "%1%"
IF NOT ERRORLEVEL 1 GOTO yes
IF ERRORLEVEL 1 GOTO no
:yes
COLOR 2
ECHO Ping OK
GOTO top
:no
COLOR 4
ECHO Ping FAIL
GOTO top
Note that in the case, the color of the whole window changes, to make individual lines of different colors, it is necessary to change the COLOR
by some external utility.
Obviously it’s just an outline, but it already has the complete logic for you to adapt as you see fit.
The line IF NOT ERRORLEVEL 1 GOTO yes
was more to show the syntax, actually the GOTO no
theoretically should suffice.
The syntax of the command is:
COLOR <cor de fundo + cor da letra em hexadecimal>
Colors available in hexadecimal:
0 preto 8 cinza escuro (seria o "preto claro" kkk)
1 azul 9 azul claro
2 verde a verde claro
3 ciano b ciano claro
4 vermelho c vermelho claro
5 magenta d magenta claro
6 amarelo e amarelo claro
7 cinza f branco
In other words, each Nibble (half byte) has 4 bits in this order: [I~] Intensity, [R] Red, [G] Green, [B] Blue:
IRGB -> binário 1011 -> hexadecimal "e" -> Amarelo claro
Effectively generating a value in this format
I R G B I R G B
^fundo^ ^frente^
Example to change the letters to strong yellow and dark green background:
color 2e
(2e
in hexadecimal is 00101110
, or G + IRG background )
Further reading:
How hexadecimal numbers work?
Coloring the output lines individually
Here’s a utility that does ECHO
colorful:
http://www.codeproject.com/Articles/17033/Add-Colors-to-Batch-Files
Follows the code adapted to colored lines separately, using the mentioned utility:
@ECHO off
:top
CECHO {08}
PING -n 1 %1% | find "%1%"
IF NOT ERRORLEVEL 1 GOTO yes
IF ERRORLEVEL 1 GOTO no
:yes
CECHO {0A}Ping OK
GOTO top
:no
CECHO {0C}:Ping FAIL
GOTO top
I believe it is not possible, when you "invoke" an application, the script will only have the "power" to do something, after this application closes.
– mau humor
in principle would have to make a loop, and individual pings within the loop.
– Bacco
and probably use an auxiliary program to change the color individually. COLOR changes the whole screen.
– Bacco