|
Answer» Greeting, I wrote tthis batch file which run a program(3Dmark06), at the beginning of the batch file I issue a Echo command which output the start time (s.txt), at the end of the batch file I also issue an Echo command which output the end time(e.txt). I would like to know if DOS Batch file can the read the end time(s.txt) and minus the Start time and output the total time which my program has run(3Dmark06). Please see my batch file for more details. Any help is greatly appreciated. Thanks/Vansky03
@echo off Echo Start Time: %date% %time%>e:\testprog\3dmark06\s.txt call e:\testprog\3dmark06\3Dmark06 -repeat=35 -res=1024x768 -gtall -cpuall -featureall -batchall -vsprofile=2_a -psprofile=2_a 3dmark.3dr -verbose echo End time: %date% %time%>e:\testprog\3dmark06\e.txt copy log*.* 3d.html
Rem Change log file from html to txt here call e:\testprog\3dmark06\htmlastext.exe /run "e:\testprog\3dmark06\convert.cfg" rem Look for passed clue here find /I "End test" e:\testprog\3dmark06\3D.txt find /I "32768 Triangles" e:\testprog\3dmark06\3D.txt if errorlevel 1 GOTO :FAIL if errorlevel 0 goto :PASS goto end
:Fail echo Results: Test Failed >e:\testprog\3dmark06\fail.txt copy e:\testprog\3dmark06\s.txt+e:\testprog\3dmark06\fail.txt+e:\testprog\3dmark06\e.txt e:\testprog\3dmark06\3dmarkh.txt goto end
:Pass Echo Results: Test Completed and Passed >e:\testprog\3dmark06\Pass.txt copy e:\testprog\3dmark06\s.txt+e:\testprog\3dmark06\pass.txt+e:\testprog\3dmark06\e.txt e:\testprog\3dmark06\3dmarkh.txt :EndNormally I would just write that batch code does not handle date/time arithmetic very well. And that is very true when compared to other scripting languages.
I found this on the net, and if precision is not your main goal, this is close enough for most government work:
Code: [Select]@echo off setlocal enableextensions :: store start time for /f "tokens=1-4 delims=:.," %%t in ("%time%") do ( set starttime=%time% set /a start100s=%%t*360000+%%u*6000+%%v*100+%%w )
:: wait for 10 seconds to simulate batch processing ping -n 11 127.0.0.1>nul
:: retrieve stop time for /f "tokens=1-4 delims=:.," %%t in ("%time%") do ( set stoptime=%time% set /a stop100s=%%t*360000+%%u*6000+%%v*100+%%w )
:: test midnight rollover. if so, add 1 day=8640000 1/100ths secs if %stop100s% lss %start100s% set /a stop100s+=8640000 set /a tooktime=%stop100s%-%start100s%
echo (%~nx0) started: %starttime% echo (%~nx0) STOPPED: %stoptime% echo (%~nx0) elapsed: %tooktime:~0,-2%.%tooktime:~-2% seconds Source
You should be able to work in your own code where the ping currently exists.
i wrote this code and it works for day laps and i hope it got no bugs
@echo off for /f "eol=E tokens=5,6,7 delims=.: " %%i in ('echo.^|time') do ( set h1=%%i set mi1=%%j set s1=%%k REM the following code is to avoid the 08 and 09 due to the set command consider REM any number that starts REM with 0 as octal and there is no octal digit 9 or 8 REM the easiest way is to convert them to hex so that they will got there same REM valyes as decimal 8 and 9 for %%r in (08,09) do ( if %%i equ %%r set /a h1= 0x%%i if %%j equ %%r set /a mi1= 0x%%j if %%k equ %%r set /a s1= 0x%%k )) set /a t1=3600*%h1%+60*%mi1%+%s1% for /f "eol=E tokens=1,2,3 delims=/" %%i in ('date /t') do ( set d1=%%i set m1=%%j set y1=%%k for %%r in (08,09) do ( if %%i equ %%r set /a d1= 0x%%i if %%j equ %%r set /a m1= 0x%%j if %%k equ %%r set /a y1= 0x%%k )) REM put ur code instead of the ping ping -n 4 10.10.10.127 >nul
for /f "eol=E tokens=5,6,7 delims=.: " %%i in ('echo.^|time') do ( set h1=%%i set mi1=%%j set s1=%%k for %%r in (08,09) do ( if %%i equ %%r set /a h1= 0x%%i if %%j equ %%r set /a mi1= 0x%%j if %%k equ %%r set /a s1= 0x%%k )) set /a t2=3600*%h1%+60*%mi1%+%s1% for /f "eol=E tokens=1,2,3 delims=/" %%i in ('date /t') do ( set d2=%%i set m2=%%j set y2=%%k for %%r in (08,09) do ( if %%i equ %%r set /a d2= 0x%%i if %%j equ %%r set /a m2= 0x%%j if %%k equ %%r set /a y2= 0x%%k )) set /a t_con=%t2%-%t1% set /a d_con=%d2%-%d1% set /a m_con=%m2%-%m1% set /a y_con=%y2%-%y1% if %t_con% LSS 0 (for /l %%q in (1,1,24) do (if %d_con% EQU %%q set /a t_con=%%q*86400+%t_con%) goto done) if %t_con% GEQ 1 (for /l %%q in (1,1,24) do (if %d_con% EQU %%q set /a t_con=%%q*86400+%t_con%)) :done set /a hour=%t_con%/3600 set /a min=(%t_con%-(%hour%*3600))/60 set /a secnds=%t_con%-(%hour%*3600)-(%min%*60) echo ur code toke %secnds% seconds ,%min% min and %hour% hour echo it passed throw %d_con% days, %m_con% month, %y_con% years pauseQuick hack - will give wrong answer if start is before midnight and end is after midnight.
Code: [Select]@echo off set timenow=%time% set nhh=%timenow:~0,2% set nmm=%timenow:~3,2% set nss=%timenow:~6,2% set ncs=%timenow:~9,2% if "%nhh:~0,1%"==" " set nhh=%nhh:~1,1% if "%nmm:~0,1%"=="0" set nmm=%nmm:~1,1% if "%nss:~0,1%"=="0" set nss=%nss:~1,1% if "%ncs:~0,1%"=="0" set ncs=%ncs:~1,1% set /a nssecs=%nss% set /a nmsecs=60*%nmm% set /a nhsecs=3600*%nhh% set /a ntimesecs=%nssecs%+%nmsecs%+%nhsecs% set /a ncentisecs=100*ntimesecs set /a ncentisecs=%ncentisecs%+%ncs% set /a msec1s=%ncentisecs%*10
REM start process to be timed REM -------------------------
echo Wait a while then press a key pause
REM ------------------------- REM end of process to be times
set timenow=%time% set nhh=%timenow:~0,2% set nmm=%timenow:~3,2% set nss=%timenow:~6,2% set ncs=%timenow:~9,2% if "%nhh:~0,1%"==" " set nhh=%nhh:~1,1% if "%nmm:~0,1%"=="0" set nmm=%nmm:~1,1% if "%nss:~0,1%"=="0" set nss=%nss:~1,1% if "%ncs:~0,1%"=="0" set ncs=%ncs:~1,1% set /a nssecs=%nss% set /a nmsecs=60*%nmm% set /a nhsecs=3600*%nhh% set /a ntimesecs=%nssecs%+%nmsecs%+%nhsecs% set /a ncentisecs=100*ntimesecs set /a ncentisecs=%ncentisecs%+%ncs% set /a msec2s=%ncentisecs%*10
set /a elapsed=%msec2s%-%msec1s% echo elapsed time %elapsed% milliseconds hi Dias de VERANO
i just want to draw ur attention if ur code handle day laps like if the program started at 23:59:00 and ended at 00:02:00 of the next day i think it will give wrong data. Quote from: .bat_man on June 04, 2008, 08:15:43 AM hi Dias de verano
i just want to draw ur attention if ur code handle day laps like if the program started at 23:59:00 and ended at 00:02:00 of the next day i think it will give wrong data.
I just want to draw your attention to the first line of my post. hi dias i dont think it was there when i read ur code for that i didnt notice itThank you much, will try and see how it work Regards/VanskyThank you Sidewinder, your code work just great..... Regards/Vansk03
|