0

I am trying to write an ASCII movie in batch, and I need the script to echo a new line at about 10-15 lines per second (hopefully that's not too confusing). By default, the script goes insanely fast, making the whole thing more difficult to see.

What I would like to do is be able to set the execution speed of the batch file, and NOT the computer itself.

Here's an example of what I'd like:

@echo off
REM Below command sets script execution speed in lines per second
setspeed=10lps
REM Ten lines of 03 begin
echo The time is 13:20:03
echo The time is 13:20:03
echo The time is 13:20:03
echo The time is 13:20:03
echo The time is 13:20:03
echo The time is 13:20:03
echo The time is 13:20:03
echo The time is 13:20:03
echo The time is 13:20:03
REM Ten lines of 03 end
REM Ten lines of 04 begin
echo The time is 13:20:04
echo The time is 13:20:04
.....

Thanks!

ditheredtransparency
  • 475
  • 3
  • 10
  • 18
  • You can use pings to create semi-reliable delays, but that's more of a hack than anything. – Carcigenicate Feb 07 '17 at 05:29
  • See for example http://stackoverflow.com/questions/29732878/delay-a-batch-file-in-under-a-second for a way to do delays. Doesn't seem to be possible in a batch file alone – Jonathan von Schroeder Feb 07 '17 at 05:31
  • Are you familiar with VBScript or .NET or Powershell or something else entirely that can compile down to a Windows Console application? Your best option I think is to use a more managed language that has a Timer construct. You set the timer to tick at the interval you want to see frames and load the next frame in the timer tick callback. – Cᴏʀʏ Feb 07 '17 at 05:35
  • Thanks for your responses, guys! @Cᴏʀʏ I don't have any knowledge with .NET, and I have very, very little knowledge with Powershell and VBScript. If it's possible, could I perform my above task using one of those better than using a batch script? – ditheredtransparency Feb 07 '17 at 05:58
  • **To anyone who needs the execution speed at about 5 lines per second:** I found that using `timeout /t 0 /nobreak >nul` in between each command slowed down the output pretty well. But in my case, this was just a little bit too slow. – ditheredtransparency Feb 07 '17 at 06:26
  • Then place it every second command? Alternatively you can use this method: `ping 1.1.1.1 -n 1 -w 500 >nul`. Note that this is not a nice method, because it will cause network traffic when trying to ping. The IP should not be an existing one, `-n 1` stands for the number of times you want to ping and `-w 500` stands for the delay to wait before declaring the connection to have a timeout. – geisterfurz007 Feb 07 '17 at 06:41
  • To limit network traffic one can use `ping 127.0.0.1 -n N -w 500`. This will wait `(N-1) * 500` milliseconds. – J.Baoby Feb 07 '17 at 09:47

4 Answers4

0

Update: I found out that if you download NirCmd (link is at the bottom of the page), it includes a "wait" command that works quite well. In my batch script, I did this:

@echo off
::This tells NirCmd to wait for 5 seconds, and then proceed to the next command.
nircmd wait 5000
echo This is one line
nircmd wait 5000
echo This is another line
nircmd wait 5000
echo Oh, hey! Another line!
nircmd wait 5000
echo Take a guess what this is... Another line!
...
ditheredtransparency
  • 475
  • 3
  • 10
  • 18
0

I like using choice commands. For instance:

@echo off
echo this is one line
choice /c q /d q /t 1 >nul
echo this is the second line

You can change the number after /t to set the seconds to wait. You can also press Q to skip the wait at any time.

Luke Deven
  • 66
  • 1
  • 8
0

In newer Windows OSes, there is the TIMEOUT command as well:

TIMEOUT /T 5

waits 5 seconds and displays a countdown like Waiting <countingDown> seconds. Proceed with any key.

TIMEOUT /T 5 > NUL

does the same without displaying anything.

TIMEOUT /T 5 /NOBREAK > NUL

additionally removes the possibility to speed up by pressing a key.

Bad thing: Only complete seconds possible, no millis.

Bowi
  • 1,378
  • 19
  • 33
0
TIMEOUT /T x > NUL    

(replace the X with the number of seconds you want)

This will do a hidden countdown because of the > NUL command at the end you won't see the countdown/pause/sleep/timer and then it will proceed with the next command. This is the best to use, as I found the Timeout command with the NUL at the end to be the best many of the other commands like Sleep and Pause do not work. You can also download NODEJS to get more functions or switch to powershell.

TIMEOUT /T 5 > NUL

Above command will give 5 second timed countdown with NO display, pressing any key will not stop it unless you use CTRL+C.

vezunchik
  • 3,669
  • 3
  • 16
  • 25
Gags
  • 1
  • Request was "about 10-15 lines per second", not "one line per 5 seconds". Besides that, please don't repeat [already existing answers](https://stackoverflow.com/a/52189003/2152082) – Stephan Mar 17 '19 at 18:40