A Windows XP help forum. PCbanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » PCbanter forum » Microsoft Windows XP » Windows XP Help and Support
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Task time duration



 
 
Thread Tools Display Modes
  #1  
Old September 16th 20, 08:06 PM posted to microsoft.public.windowsxp.help_and_support
No_Name
external usenet poster
 
Posts: 4
Default Task time duration

I am running a Robocopy task using a a script in a .bat file. What command lines would I have to incorporate into the script that will post somewhere (i.e. a text file) the start and ending time of the task so its duration can be ascertained? This does not seem possible directly from Robocopy itself, despite its multitude of switches.

All suggestions appreciated.
Ads
  #3  
Old September 17th 20, 02:44 PM posted to microsoft.public.windowsxp.help_and_support
JJ[_14_]
external usenet poster
 
Posts: 46
Default Task time duration

On Wed, 16 Sep 2020 12:06:50 -0700 (PDT), wrote:
I am running a Robocopy task using a a script in a .bat file. What
command lines would I have to incorporate into the script that will post
somewhere (i.e. a text file) the start and ending time of the task so its
duration can be ascertained? This does not seem possible directly from
Robocopy itself, despite its multitude of switches.

All suggestions appreciated.


You can use JScript via MSHTA to get a number which is a timestamp of the
current time (since January 1st 1970) in milliseconds unit (1 second =
1000ms).

But because batch file can only handle signed 32-bit integer number (i.e.
from -2147483648 to 2147483647), and the timestamp number is larger than
2147483647, JScript is needed to calculate the timestamp difference (the
duration), as well as displaying the duration in a more meaningful format
such as: 1 hours, 10 minutes, 34.123 seconds.

e.g. (warning: long text)
note: the JScript code doesn't support time duration longer than a year.

Code:
@echo off
setlocal

rem get timestamp at start of task
call :GetTimestamp ts1
echo start timestamp = %ts1%

rem do time consuming task... this sample task takes about 4 seconds.
for /l %%A in (0,1,200000) do rem.

rem get timestamp at end of task
call :GetTimestamp ts2
echo end timestamp = %ts2%

rem get difference between two timestamps
call :CalcTimestampDelta td %ts2% %ts1%
echo timestamp delta = %td%

rem display duration
call :DurationStr d %td%
echo duration = %d%
goto :eof

:GetTimestamp {ResultVarName}
for /f %%A in ('mshta "javascript:(new ActiveXObject('scripting.filesystemobject')).getstandardstream(1).writeline((new Date()).getTime());close()"') do set %1=%%A
goto :eof

:CalcTimestampDelta {ResultVarName} {Timestamp1} {Timestamp2}
for /f %%A in ('mshta "javascript:(new ActiveXObject('scripting.filesystemobject')).getstandardstream(1).writeline(Math.abs(%3-%2));close()"') do set %1=%%A
goto :eof

:DurationStr {ResultVarName} {TimestampDelta}
for /f "delims=" %%A in ('mshta "javascript:t=new Date(%2);r=(t.getUTCSeconds()+t.getUTCMilliseconds()/1000)+' seconds';h=t.getUTCDate()*24+t.getUTCHours();r=((m=t.getUTCMinutes())||h?m+' minutes'+(r?' ':''):'')+r;r=(h?h+' hours'+(r?' ':''):'')+r;(new ActiveXObject('scripting.filesystemobject')).getstandardstream(1).writeline(r);close()"') do set %1=%%A
goto :eof
  #4  
Old October 14th 20, 05:23 PM posted to microsoft.public.windowsxp.help_and_support
Ivan Denisovich
external usenet poster
 
Posts: 16
Default Task time duration

On Wednesday, September 16, 2020 at 3:48:04 PM UTC-5, Barry Schwarz wrote:
On Wed, 16 Sep 2020 12:06:50 -0700 (PDT),
wrote:
I am running a Robocopy task using a a script in a .bat file. What command lines would I have to incorporate into the script that will post somewhere (i.e. a text file) the start and ending time of the task so its duration can be ascertained? This does not seem possible directly from Robocopy itself, despite its multitude of switches.

All suggestions appreciated.

Before calling Robocopy: time /T filename.txt

After Robocopy returns: time /T samefilename.txt

--
Remove del for email

Many thanks for your help
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off






All times are GMT +1. The time now is 09:03 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 PCbanter.
The comments are property of their posters.