Reputation: 293
In a CMD batch trigger script I use a cleartool
command to write activity information to a file:
cleartool lsactivity -long %CLEARCASE_ACTIVITY%>>C:\folder\activityinfo.txt
This works almost every time but occasionally for a reason unknown to me the cleartool command does not write the information correctly to file resulting in a 0KB output file that I cannot delete. Whatsmore it blocks the trigger from running properly in successive attempts.
I wrote some code that checks to see whether the output file is 0KB in size but that doesn't work because the cleartool command seems to keep the file open even though it isn't writing to it. It's so strange!
After a number of hours the trigger works again because I assume the locked process unlocks.
Is there any way to avoid this phenomenon?
Regards,
Andrew
Upvotes: 1
Views: 707
Reputation: 1324347
What I have seen done is to write to a different file for each occurrence of the cleartool lsactivity
, and to aggregate those files into one, once the full process is done.
One technique, for instance, would be to use the date in the filename, as in "Batch command date and time in file name".
set hr=%time:~0,2%
if "%hr:~0,1%" equ " " set hr=0%hr:~1,1%
cleartool lsactivity -long %CLEARCASE_ACTIVITY% > C:\folder\activityinfo_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%.txt
Note that I only use '>
', not '>>
', since the file 'activityinfo_YYYYMMDD_HH:MM:SS
' is always different at each cleartool invocation.
I have set the
cleartool lsactivity
command to write to (or overwrite) the files with '>
' instead of '>>
' (append).Also, since sometimes there are hiccups in the system, I set a sleep of 5 seconds after the command just in case there is a delay in writing to and creating the file
From the comments below, though, adding a sleep at the beginning of the script is also recommended:
I have added an initial sleep of 20 seconds at the beginning of the script and I haven't had any problems yet.
Upvotes: 1