输出的文本不能含有特殊字符

    1. @echo off
    2. SETLOCAL EnableDelayedExpansion
    3. for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
    4. set "DEL=%%a"
    5. )
    6. rem echo say the name of the colors, don't read
    7. :start
    8. rem cls
    9. call :ColorText 0a "blue"
    10. call :ColorText 0C "green"
    11. call :ColorText 0b "red"
    12. echo.
    13. call :ColorText 19 "yellow"
    14. call :ColorText 2F "black"
    15. call :ColorText 4e "white"
    16. echo.
    17. echo aaaaaa
    18. pause
    19. goto :eof
    20. :ColorText
    21. echo off
    22. <nul set /p ".=%DEL%" > "%~2"
    23. findstr /v /a:%1 /R "^$" "%~2" nul
    24. del "%~2" > nul 2>&1
    25. goto :eof

    方法二

    1. @echo off
    2. call :colortheword "将着色的字符" 37 "使用默认颜色显示"
    3. goto :eof
    4. rem 在参数中<>为必选项,[]为可选项,调用参数:<str1=将着色的字符> [str2=颜色设置] [str3=正常显示字符]
    5. :colortheword <str1=将着色的字符> [str2=颜色设置] [str3=正常显示字符]
    6. set "objFile=%~1"
    7. set "objColor=07"&if not "%~2."=="." set "objColor=%~2"
    8. set "objMsg= "&if not "%~3."=="." set "objMsg=%~3"
    9. for /F %%a in ('"prompt $h & for %%b in (1) do rem"')do set /p="%%a%objMsg%"<nul>"%objFile%"
    10. findstr /a:%objColor% .* "%objFile%" nul
    11. del /q "%objFile%" >nul 2>nul
    12. goto :eof