When i run the batch file on VS code, the color does not appear and shows the raw code.
echo off echo %ESC%[42mCan support unscramble your logs?%ESC%[0m When i run the code manually, it does not show the color and show the raw code as well.
echo %ESC%[42mCan support unscramble your logs?%ESC%[0m Any ideas? I'm on Windows 10, without admin rights.
Yesterday i tried to run this batch file on VS code and the color changed.
However for cmd.exe, it will still display the raw code without any colors.
Been referencing to multiple questions e.g.
2 Answers
You need to define the ESC environment variable:
for /F %a in ('echo prompt $E ^| cmd') do @set "ESC=%a" Then you can use it, e.g. as follows:
echo ^<ESC^>[4m %ESC%[4mUnderline Underline%ESC%[0m echo ^<ESC^>[32m %ESC%[32mGreen Green Green%ESC%[0m echo ^<ESC^>[33m %ESC%[33mYellow Yellow Yellow%ESC%[0m Result:
Test from a batch script using the following code snippet:
@ECHO OFF SETLOCAL EnableExtensions DisableDelayedExpansion for /F %%a in ('echo prompt $E ^| cmd') do ( set "ESC=%%a" ) echo ^<ESC^>[4m %ESC%[4mUnderline DisableDelayedExpansion%ESC%[0m SETLOCAL EnableDelayedExpansion echo !ESC