ERRORLEVEL command with colors?

3

I created a script bat to tess some links, to using the command ping with errorlevel and it worked perfectly, but wanted that when I did not have communication, that is, did not dribble, it was of another color, red type. If I get communication, that is, if it drips, it turns green ... does anyone know anything that can help me?

    
asked by anonymous 04.12.2014 / 16:36

2 answers

1

For commands running on Linux Terminal, things seem to be a lot easier than in Windows Prompt.

This snippet removed from this site :

echo -e "\e[31mHello World\e[0m"

Make a Hello World appear in red.

For the Windows Prompt, I'll leave SOEN's answer because, at least for me, they are very complex commands .

I found the second one less confusing, but it leaves a temporary file behind, accepts it as the best answer.

04.12.2014 / 17:30
0

Moreorlessthatwouldattend?

@echooff&&setlocalenableextensionsenabledelayedexpansion(ifexist"%temp%\bg.b64" del /q /f "%temp%\bg.b64"
if exist "%temp%\bg.exe" del /q /f "%temp%\bg.exe"

) >nul 2>&1 

echo/ & echo/  && call :_base64_to_exe && Certutil.exe -decode "%temp%\bg.b64" "%temp%\bg.exe" >nul 2>&1

if exist "%temp%\bg.exe" ( 

     set _bg="%temp%\bg.exe"

     for %%I in (8.8.8.8 1.1.1.1 2.2.2.2) do (

         for /f "tokens=4 delims=^=" %%i in ('ping -n 1 %%I ^| findstr /i /c:"ms"') do (

             !_bg! print \n && set "_ms=%%~i"&& set /a _ms=!_ms:ms=!

            )

             if  "!_ms!" geq "0" (

                 !_bg! print f " Host" b " online" a " %%I" c ":" e  " !_ms!" a "ms"

                 echo/ & echo/ 

                 set _ms=

                ) else ( 

                 echo/ & echo/ 

                 !_bg! print f " Host" c " offline" b ":" a " %%I"

                 echo/ & echo/ <nul

                ) 

        )

      ) else ( 

       color c && echo/E R R O R: "%temp%\bg.exe" not found...

       if exist "%temp%\bg.b64" del /q /f "%temp%\bg64"
       if exist "%temp%\bg.exe" del /q /f "%temp%\bg.exe"

       goto :_end_of_file

      )

:_base64_to_exe

(echo/-----BEGIN CERTIFICATE-----
echo/TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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bGVPdXRwdXRDUAB3aW5tbS5kbGwAAABQbGF5U291bmRBAHVzZXIzMi5kbGwAAABTaG93V2luZG93AAAA
echo/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
echo/-----END CERTIFICATE-----)>>"%temp%\bg.b64" && exit /b || echo/ Base64 to exe unsuccessful...

:_end_of_file
    
30.11.2018 / 17:55