How to echo with different colors in the Windows command line

前端 未结 23 1572
野性不改
野性不改 2020-11-22 08:55

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.

23条回答
  •  一向
    一向 (楼主)
    2020-11-22 09:51

    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
    

提交回复
热议问题