How to have multiple colors in a Windows batch file?

前端 未结 12 1601
我寻月下人不归
我寻月下人不归 2020-11-22 01:05

I was wondering if its possible to have different colored text on the same line in a Windows batch file, for example if it says

echo hi world
12条回答
  •  滥情空心
    2020-11-22 01:24

    Several methods are covered in
    "51} How can I echo lines in different colors in NT scripts?"
    http://www.netikka.net/tsneti/info/tscmd051.htm

    One of the alternatives: If you can get hold of QBASIC, using colors is relatively easy:

      @echo off & setlocal enableextensions
      for /f "tokens=*" %%f in ("%temp%") do set temp_=%%~sf
      set skip=
      findstr "'%skip%QB" "%~f0" > %temp_%\tmp$$$.bas
      qbasic /run %temp_%\tmp$$$.bas
      for %%f in (%temp_%\tmp$$$.bas) do if exist %%f del %%f
      endlocal & goto :EOF
      ::
      CLS 'QB
      COLOR 14,0 'QB
      PRINT "A simple "; 'QB
      COLOR 13,0 'QB
      PRINT "color "; 'QB
      COLOR 14,0 'QB
      PRINT "demonstration" 'QB
      PRINT "By Prof. (emer.) Timo Salmi" 'QB
      PRINT 'QB
      FOR j = 0 TO 7 'QB
        FOR i = 0 TO 15 'QB
          COLOR i, j 'QB
          PRINT LTRIM$(STR$(i)); " "; LTRIM$(STR$(j)); 'QB
          COLOR 1, 0 'QB
          PRINT " "; 'QB
        NEXT i 'QB
        PRINT 'QB
      NEXT j 'QB
      SYSTEM 'QB
    

提交回复
热议问题