Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-20-2013, 04:39 AM   PM User | #1
Justsawyer
New Coder

 
Join Date: Nov 2012
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Justsawyer is an unknown quantity at this point
Question Rainbow Text in Command Prompt

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
Attached Thumbnails
Click image for larger version

Name:	rainbow.png
Views:	56
Size:	13.0 KB
ID:	11872  
Justsawyer is offline   Reply With Quote
Old 01-20-2013, 03:14 PM   PM User | #2
AceInfinity
New Coder

 
Join Date: Jan 2013
Location: Canada
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
AceInfinity is an unknown quantity at this point
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.



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:
Code:
@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
AceInfinity is offline   Reply With Quote
Old 01-20-2013, 06:18 PM   PM User | #3
Justsawyer
New Coder

 
Join Date: Nov 2012
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Justsawyer is an unknown quantity at this point
Macintosh

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 :/
Attached Thumbnails
Click image for larger version

Name:	pics.png
Views:	33
Size:	28.9 KB
ID:	11876  

Last edited by Justsawyer; 01-20-2013 at 07:05 PM..
Justsawyer is offline   Reply With Quote
Old 01-20-2013, 10:02 PM   PM User | #4
Justsawyer
New Coder

 
Join Date: Nov 2012
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Justsawyer is an unknown quantity at this point
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:
Attached Thumbnails
Click image for larger version

Name:	dsdsdsdsdsdsds.png
Views:	21
Size:	13.1 KB
ID:	11877  
Justsawyer is offline   Reply With Quote
Old 01-20-2013, 11:30 PM   PM User | #5
AceInfinity
New Coder

 
Join Date: Jan 2013
Location: Canada
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
AceInfinity is an unknown quantity at this point
Why does the first argument have the filename and extension while you put a wildcard on a filename following another extension afterwards?
Code:
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?....
AceInfinity is offline   Reply With Quote
Old 01-20-2013, 11:52 PM   PM User | #6
Justsawyer
New Coder

 
Join Date: Nov 2012
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Justsawyer is an unknown quantity at this point
whats %0? ^_^ i'm a complete noobly to mostly all coding
Justsawyer is offline   Reply With Quote
Old 01-20-2013, 11:53 PM   PM User | #7
AceInfinity
New Coder

 
Join Date: Jan 2013
Location: Canada
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
AceInfinity is an unknown quantity at this point
Try it for yourself:
Code:
echo %0
AceInfinity is offline   Reply With Quote
Old 01-22-2013, 05:13 AM   PM User | #8
Justsawyer
New Coder

 
Join Date: Nov 2012
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Justsawyer is an unknown quantity at this point
lol done http://www.codingforums.com/showthread.php?t=286173
Justsawyer is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:23 PM.


Advertisement
Log in to turn off these ads.