CMD batch file calling cleartool command freezes script when writing to file

半世苍凉 提交于 2019-12-08 04:00:37

问题


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


回答1:


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.

The OP Andrew comments:

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.



来源:https://stackoverflow.com/questions/14998729/cmd-batch-file-calling-cleartool-command-freezes-script-when-writing-to-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!