Hello, I am trying to clear the contents of a log file app1.log which is being used by a server.
I am using windows 2003.Following are the commands I tried so far.
command: echo on>app1.log
output: The process cannot access the file because it is being used by another processcommand:type nul>app1.log
output: The process cannot access the file because it is being used by another processcommand:type app1.log>NUL>app1.log
output: The process cannot access the file because it is being used by another processI am able to open the file, select content,delete and save the file under same name - manually.
Can some one Please suggest how to put this in a batch script.Thank You.
not sure, is win2003 equiv. to winME?
maybe try:
echo on>fil
xcopy /r /y fil app1.log
if you can do it manually, you should be able to do it from batch, otherwise, when you did it manually via notepad or edit, it should have given the same error of access denied.
also not clear if the app1.log is on "your" (local) machine or if you're trying to delete it from server. it might be a file-privelage issue.
wow it worked !!
Thanks soo much.
You could also use an agressive loop, to try until success. If you use DEL or TYPE (with redirect) or XCOPY, that may not matter a lot if the issue is time related: :begin
del app1.log
if NOT exist app1.log goto end
echo app1.log still exists... retrying...
goto begin
:endNote that if the process which is writing to the file, is a very fast one, it may occur that the file gets recreated between the DEL and the IF command.
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |