How to script time in DOS?

How do you click a script in a DOS prompt?

The * NIX equivalent would be:

$ time myscript real 0m0.886s user 0m0.846s sys 0m0.031s $ 

Is there a DOS equivalent? Thanks

+4
source share
4 answers

you can put this at the beginning and end of your party:

 echo %time% 
+5
source

you can use timeit.exe from the Windows Server 2003 Resource Kit . You can also use other useful Unix tools and command ports.

 C:\Documents and Settings\Rob>timeit sleep 3 Version Number: Windows NT 5.1 (Build 2600) Exit Time: 2:40 pm, Thursday, December 10 2009 Elapsed Time: 0:00:03.296 Process Time: 0:00:00.015 System Calls: 7576 Context Switches: 1974 Page Faults: 1072 Bytes Read: 6172 Bytes Written: 11086 Bytes Other: 144432 
+5
source

This is a DOS script package that will calculate the time difference for you, and not just do echo %time% .

The following code will work fine until your "time-user section" takes more than 24 hours. Please forgive or give me suggestions, this is an incomplete work in which I spent about an hour.

Replace โ€œPAUSEโ€ with a call to your script at the time of your own code.

DOS BAT FOLLOWS FILE:

Note: has been edited to fix the issue when leading zeros were octal rather than decimal.

Note: has been edited to handle work on "midnight", as well as output leading zeros at the output.

 @echo off @rem -------------------------------------------- setlocal ENABLEEXTENSIONS set start_time=%time% echo Beginning at: %start_time% echo Running Timed Batch File echo. @rem echo %* <-- Extension for all args -- easier than following line @rem echo %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 ... ... @rem DO YOUR WORK HERE -- see "call" / PAUSE is here to "fake" work @rem call userscript.bat %* PAUSE set stop_time=%time% echo. echo Timed Batch File Completed echo Start time: %start_time% echo Stop time : %stop_time% set TEMPRESULT=%start_time:~0,2% call:FN_REMOVELEADINGZEROS set start_hour=%TEMPRESULT% @rem set TEMPRESULT=%start_time:~3,2% call:FN_REMOVELEADINGZEROS set start_min=%TEMPRESULT% @rem set TEMPRESULT=%start_time:~6,2% call:FN_REMOVELEADINGZEROS set start_sec=%TEMPRESULT% @rem set TEMPRESULT=%start_time:~9,2% call:FN_REMOVELEADINGZEROS set start_hundredths=%TEMPRESULT% set TEMPRESULT=%stop_time:~0,2% call:FN_REMOVELEADINGZEROS set stop_hour=%TEMPRESULT% @rem set TEMPRESULT=%stop_time:~3,2% call:FN_REMOVELEADINGZEROS set stop_min=%TEMPRESULT% @rem set TEMPRESULT=%stop_time:~6,2% call:FN_REMOVELEADINGZEROS set stop_sec=%TEMPRESULT% @rem set TEMPRESULT=%stop_time:~9,2% call:FN_REMOVELEADINGZEROS set stop_hundredths=%TEMPRESULT% set /A start_total=(((((%start_hour%*60)+%start_min%)*60)+%start_sec%)*100)+%start_hundredths% set /A stop_total=(((((%stop_hour%*60)+%stop_min%)*60)+%stop_sec%)*100)+%stop_hundredths% set /A total_time=%stop_total% - %start_total% set /A total_hundredths=%total_time% %% 100 set total_hundredths=00%total_hundredths% set total_hundredths=%total_hundredths:~-2% set /A total_time=%total_time% / 100 set /A total_sec="%total_time% %% 60" set total_sec=00%total_sec% set total_sec=%total_sec:~-2% set /A total_time=%total_time% / 60 set /A total_min="%total_time% %% 60" set total_min=00%total_min% set total_min=%total_min:~-2% set /A total_time=%total_time% / 60 set /A total_hour="%total_time% %% 60" @rem Handle if it wrapped around over midnight if "%total_hour:~0,1%"=="-" set /A total_hour=%total_hour% + 24 echo Total time: %total_hour%:%total_min%:%total_sec%.%total_hundredths% @rem -------------------------------------------- @rem Exit the BAT Program endlocal goto END @rem -------------------------------------------- @rem FN_REMOVELEADINGZEROS function @rem Used to remove leading zeros from Decimal @rem numbers so they are not treated as Octal. :FN_REMOVELEADINGZEROS if "%TEMPRESULT%"=="0" goto END if "%TEMPRESULT:~0,1%" NEQ "0" goto END set TEMPRESULT=%TEMPRESULT:~1% goto FN_REMOVELEADINGZEROS @rem -------------------------------------------- @rem BAT PROGRAM / FUNCTION FILE EXIT :END 
+3
source

If you do not mind using a third-party EXE for reference, timer.exe from Gammadyne is very useful.

 setlocal ENABLEEXTENSIONS FOR /F %%G IN ('timer') DO SET start_time=%%G @rem Do your work Here call userscript.bat %* timer %start_time% "Total time" endlocal 
0
source

All Articles