Answer the question
In order to leave comments, you need to log in
How to change line color in CMD?
I myself don’t understand a damn thing in cmd, so I looked for a solution on the Internet.
As far as I understand, color is not used for this. it changes color throughout the session. But they use some kind of hack with the findstr command , which can explicitly specify the color of the message it displays.
Here's what dug up:
:write
setlocal
:write1
set "tempFolder=%TEMP%\%~n0.%time:~-2%.%random%"
md "%tempFolder%" 2>nul || goto write1
pushd %tempFolder%
set /p .=.<nul>"%~2"
findstr /a:%~1 /c:"." /s "%~2"
popd
rd /s /q "%tempFolder%" 2>nul
endlocal & exit /b
:writeLn
call :write %1 "%~2"
echo:
exit /b
call :write 0A "My Charona"
will return My Charona:.
, where My Charona and the colon will be green, and the period will be the default. findstr /a:%~1 /c:"." /s "%~2"
), some are black magic ( set /p .=.<nul>"%~2"
). Answer the question
In order to leave comments, you need to log in
set /p .=.<nul>"%~2"
- writes a dot to the file "%~2" without a newline.
The standard option echo .>"%~2"
is to add line feed/carriage return characters at the end of the file. findstr /a:%~1 /c:"." /s "%~2"
- searches for a point in the file "%~2" and displays it in the color specified in "%~1". Due to the presence of the /s key, the name of the file in which the point was found is displayed, and the previous command creates a file with a name equal to the search phrase, i.e. the effect of the output of the phrase is created.
You can get rid of the dot by replacing it with a space, but I don’t think you can get rid of the colon.
In general, this does not look like a normal way of output. If you really want colored letters in a batch file, then look towards nircmd or similar multifunctional command line utilities, perhaps there is such a feature there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question