bat echo輸出內容指定顏色

bat echo 輸出內容爲不一樣的顏色

先看代碼:html

複製代碼
@echo off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  set "DEL=%%a"
)
rem echo say the name of the colors, don't read
:start
rem cls
call :ColorText 0a "blue"
call :ColorText 0C "green"
call :ColorText 0b "red"
echo.
call :ColorText 19 "yellow"
call :ColorText 2F "black"
call :ColorText 4e "white"

echo.
echo aaaaaa

pause

goto :eof

:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
複製代碼

使用注意事項:post

1.你的代碼放在 :start 和第一行 goto :eof之間字體

2.換行使用 echo.this

3.最好使用雙引號把內容括起來,否則遇到空格就會報拒絕訪問的錯誤,內容若是包含特殊字符(例如:"a:!aa" 等等,通常是win不容許咱們用來命名文件的符號),也可能致使報錯,或者字符不顯示,因此最好不要使用特殊字符,這個會在當前目錄生成一個臨時文件,以你的內容爲命名,若是包含了那些字符,就會產生那些文件,最好不刪除,須要本身手動刪除。spa

4.關於顏色,有背景色和字體色,第一個數字表明背景色,第二個數字表明字體色,至於顏色值,在 cmd 中輸入 color /? 查看code

 

出處:https://www.cnblogs.com/ibingshan/p/10906622.htmlhtm

相關文章
相關標籤/搜索