0

I would like to make this command loop for 30 seconds then say done:

@Echo off
pause
Title Matrix
Color 0A
:top
Echo %Random%%Random%%Random%%Random%%Random%­%Random%%Random%%Random%%Random%%Random%­%Random%%Random%%
(not loop the pause, just the %random%)
5
  • 1
    Could you try to search first?
    – VL-80
    Dec 5, 2013 at 1:18
  • Fixed your formatting, please double check that your code looks correct.
    – nerdwaller
    Dec 5, 2013 at 1:20
  • @Nikolay: This question asks how to loop until a certain amount of time has elapsed, and then exit. The question you referenced does not address that facet. Dec 5, 2013 at 1:42
  • by "loop for 30 seconds" you mean sleep for 30 seconds after running the commands, or running commands 30 times ?
    – Anis H
    Dec 5, 2013 at 1:51
  • @Scott, you're right, but my point was to demonstrate that search can help. I found the link which I provided within 5 seconds after I saw the question. I believe that by spending 5-10 minutes one can find exact solution on one or another web site, since the question appears to be not super rare.
    – VL-80
    Dec 5, 2013 at 2:14

1 Answer 1

0

This may just work

@echo off

set looptime=30
set /a "T1=(%time:~6,2% + %looptime% ) %% 60"

:loop
  Echo %Random%%Random%%Random%%Random%%Random%­%Random%%Random%%Random%%Random%%Random%­%Random%%Random%%
  set T2=%time:~6,2%
  if not %T1% == %T2% goto loop

:: continue with whatever
2
  • This, technically, does answer the question as asked -- but the question, as asked, implies a broader question. If the body of the loop (an echo statement, in the example) takes more than a second (or, for that matter, if your task gets pre-empted for more than a second), your solution might get consecutive values for T2 that are non-consecutive integers, and so might skip over the value of T1. Also, if the requested duration is more than 60 seconds, your solution will run for only looptime % 60 seconds. Dec 5, 2013 at 20:03
  • @Scott you're right but this was not intended as a general all loop solution, just a particular solution to a very narrow and particular situation.
    – gonzalezea
    Dec 6, 2013 at 1:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .