PCbanter

PCbanter (http://www.pcbanter.net/index.php)
-   Windows XP Help and Support (http://www.pcbanter.net/forumdisplay.php?f=15)
-   -   Task time duration (http://www.pcbanter.net/showthread.php?t=1110848)

[email protected] September 16th 20 08:06 PM

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.

Barry Schwarz[_3_] September 16th 20 09:47 PM

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.


Before calling Robocopy: time /T filename.txt

After Robocopy returns: time /T samefilename.txt

--
Remove del for email

JJ[_14_] September 17th 20 02:44 PM

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


Ivan Denisovich October 14th 20 05:23 PM

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


All times are GMT +1. The time now is 01:42 AM.

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