ivan rosa
asked on
Defining time in batch
Hello folks,
I have this endless loop below, but I'm trying to get it running for let's say 1 minute duration, how would I set the condition for time?
I have this endless loop below, but I'm trying to get it running for let's say 1 minute duration, how would I set the condition for time?
@echo off
cls
:start
echo "starting loop"
ping www.sitetotest.com >>log.txt
goto start
ASKER
please a ps1 or a vbs are always welcome
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here is an example of a Powershell approach that you could adapt.
https://mjolinor.wordpress.com/2012/01/14/making-a-timed-loop-in-powershell/
~bp
https://mjolinor.wordpress.com/2012/01/14/making-a-timed-loop-in-powershell/
~bp
Here's a simple example of how to do it in VBS:
Wscript.Echo Now
EndTime = Timer + 10 ' seconds
Do
' run ping command here
Wscript.Sleep 1000 ' millisecoinds
Loop While Timer < EndTime
Wscript.Echo Now
~bp
ASKER
super! bill you are a beast!
Welcome, glad that was helpful, thanks for the feedback.
~bp
~bp
https://www.experts-exchange.com/questions/27840118/Generate-Time-Elapsed-in-Batch-file.html
If you wanted to work in Powershell or VBS instead they can readily do these types of calculations, but not sure that works for you.
Would it be okay for you to leverage a "stopwatch" type add on EXE from your BAT script. There are several of these (I mention one in that link above) that you could potentially use to calculate the elapsed time and wait until it exceeded your desired interval, like 1 minute. Would that be feasible?
~bp