Batch - Countup Timer -


i'm trying make countup timer in batch , far, have this

:timer set time=0 :time set /a time=%time%+1 ping localhost -n 2 >nul goto time 

the problem is, want run @ same time event happening in same batch file. how can this?

are wanting time how long takes execute batch script? if have powershell installed can use measure-command cmdlet.

save timeit.bat:

@echo off >~timeit-%~n1.bat echo(%* powershell "measure-command {start-process ~timeit-%~n1.bat -wait}" del ~timeit-%~n1.bat 

then when want time execution of something, say, systeminfo, timeit systeminfo.


if prefer non-powershell solution (as powershell takes several annoying seconds prime in first run per windows session), here's faster batch / jscript hybrid solution (more info). executes command in same window, whereas powershell solution spawns new window command. save timer.bat:

@if (@a==@b) @end   /*  begin multiline jscript comment  :: timer.bat command args :: measures execution time of command @echo off & setlocal  if "%~1"=="" (     echo usage: %~nx0 command args     goto :eof ) cscript /nologo /e:jscript "%~f0" %* goto :eof  :: end batch portion / begin jscript */ var osh = new activexobject('wscript.shell'), cmd = [], b4 = new date();  (var i=0; i<wsh.arguments.length; i++) {     var arg = wsh.arguments(i);     cmd.push(/\s/.test(arg) ? '"' + arg + '"' : arg); }  var exe = osh.exec('cmd /c ' + cmd.join(' ')); while(!exe.stdout.atendofstream) wsh.echo(exe.stdout.readline())  var x = (new date() - b4) / 1000,     d = math.floor(x / 86400),     d = d ? d + ' days ' : '',     h = ('0' + (math.floor(x / 3600) % 24)).slice(-2),     m = ('0' + (math.floor(x / 60) % 60)).slice(-2),     s = math.floor(x % 60) + x % 1,     s = (s < 10) ? '0'+s : s;  wsh.echo('\r\nexecution completed in ' + d + h + ':' + m + ':' + s); 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -