...

View Full Version : Rainbow Text in Command Prompt



Justsawyer
01-20-2013, 05:39 AM
So I'm coding a silly little program in .bat for command prompt, and can't seem to figure out how colors and text work? This is what I have so far:

@echo off
:start
color 02
echo I eat poop
goto start


but it is just 1 color, I want it to change the text color but have the same text every time, or maybe diffrent text, that doesn't matter, just a diffrent color every line, say like this:

@echo off
:start
color 02
echo I eat poop
color 03
echo I eat poop
color 04
echo I eat poop
color 05

goto start


I've tried that but it just keeps the text one color :( any help? also picture below

AceInfinity
01-20-2013, 04:14 PM
By default you can't do this, there's no way to structurally have multiple colors by the calling color.exe because it's designed to change the full console's text. There is a work around fortunately.

http://i.imgur.com/Ou7Dlxe.png

Using prompt.exe you can use Escape codes in a manner that enables you to have multiple colors in the console. Prompt.exe enables you to change the command prompt. For more information type "prompt /?" (without quotes), in your cmd prompt.

Example:

@echo off
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
SETLOCAL EnableDelayedExpansion

call :C F0 "Color"
call :C A0 "Change"
echo.
pause && goto :eof

:C
echo off
<nul set /p ".=%DEL%" > "%Temp%\%~2"
cd %Temp%
findstr /v /a:%1 /R "^$" "%~2" nul
del "%Temp%\%~2" > nul 2>&1
goto :eof

Justsawyer
01-20-2013, 07:18 PM
Thanks ^_^ works great, I don't really understand the top and bottom code , but this is what it got from it:

@echo off
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
SETLOCAL EnableDelayedExpansion
:start
call :C C0 "POOP`"
call :C E0 "POOP`"
call :C A0 "POOP`"
call :C B0 "POOP`"
goto start


echo.
pause && goto :eof

:C
echo off
<nul set /p ".=%DEL%" > "%Temp%\%~2"
cd %Temp%
findstr /v /a:%1 /R "^$" "%~2" nul
del "%Temp%\%~2" > nul 2>&1
goto :eof


It works fine, but it would be nice if it printed faster, it takes about 20 seconds to fill the whole command prompt, anyway to make it faster? also moar pics in the bottem

Also this same code works when on my hardrive, but not when on a flashdrive :/

Justsawyer
01-20-2013, 11:02 PM
also ALSO my copy script isn't working either trying to copy the fil

COPY F:\batrainbow.bat*.* C:\
pause

batrainbow.bat being the colorful poop repeating file, but when I run it it gives me this:

AceInfinity
01-21-2013, 12:30 AM
Why does the first argument have the filename and extension while you put a wildcard on a filename following another extension afterwards?

filename.ext*.*

Also, you have to run this script as admin if you're copying to the Windows installation drive (C:\), and instead of the full filepath why don't you just use %0?....

Justsawyer
01-21-2013, 12:52 AM
whats %0? ^_^ i'm a complete noobly to mostly all coding

AceInfinity
01-21-2013, 12:53 AM
Try it for yourself:

echo %0

Justsawyer
01-22-2013, 06:13 AM
lol done http://www.codingforums.com/showthread.php?t=286173



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum