[Batch] WaitDisplay "Animation" In Console Example

AceInfinity

Emeritus, Contributor
Joined
Feb 21, 2012
Posts
1,728
Location
Canada
Here's an example I put together for the "." "..", "..." animation inside of the cmd prompt from a batch script.

What is cool about this, is, you can actually change the text before the "..." animation if you wanted, because this variable is used as param %1 in the called function.

Take a look at my script. Run it. And you'll see what i'm talking about.

Code:
::---------------------------------
::WaitDisplay
::Created by AceInfinity - 2012©
::---------------------------------

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
set /a numtimes=3
FOR /l %%G in (1,1,%numtimes%) DO (
	CALL :WaitDisplay "Please Wait"
)

SETLOCAL DISABLEDELAYEDEXPANSION
CLS
ECHO Done! Press any key to finish...

pause > NUL && GOTO :EOF

:WaitDisplay
SET string=%1
SET string=%string:"=%
SET dots=...

FOR /l %%G in (1,1,3) DO (
	CLS
	ECHO !string!!dots:~0,%%G!
	PING localhost -n 2 -w 500 -l 5000 > NUL
)

Enjoy
:beerchug2:
 
Nice script - it runs nicely.

How would you use this as a loading screen for another action that happens in the background? I tried adding in a couple of commands, but any action I tried happened after the loop stopped. Would the easiest way be to call another bat script at the beginning of the loop, and how could I link the animation to end once the called bat script exits (or whatever routine I want to run finishes).
 
How would you use this as a loading screen for another action that happens in the background?

that happens in the background? - Oohh, I don't think so lol. Batch is not really suited for multi-threading. A scripting language like Perl is, but not batch. Thus this would be more of a delay if you used it as a loading screen, just for the visual :)

Because you'd have to display the "Message..." before starting the app through the command line. The way I would attempt it though:

Code:
CALL :WaitDisplay "Please Wait" %%G

Check param %2 in the :WaitDisplay portion for if it's equal to 1 (the value of the first in the batch for loop). And if so, then start the program.

Note: I haven't tested this, but you could try it :) See what you come up with. I wouldn't do it directly in the loop through checking for %%G though because i'm pretty positive that this will not work, but again, I haven't tested anything yet. I could if you wanted, and were struggling, but determined enough to get this working? lol

~Ace
 

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top