1

I have a batch script that unzips some files from a folder and this script may be called several times.

For unzipping I use unzip.exe and I log it to a log file. For instance this is what goes into this logfile:

ECHO %DATE% - %TIME% >> Unzipped.log
ECHO ERROR LEVEL IS: !ERRORLEVEL! >> Unzipped.log
ECHO Error with file %1 >> Unzipped.log

My question is, is it possible to get a file lock on "Unzipped.log" file, if my batch script is called several times in a short time period?

I've tried to google this but with no luck. The only time where I have seen a problem is when I open the "Unzipped.log" file in Word, than my batch script won't write to it. When I have it open in Notepad/Notepad++ there is no problem in writing to the log file.

Oliver Nilsen
  • 1,017
  • 2
  • 12
  • 32

1 Answers1

2

Yes, you most definitely can get a failure due to file locking if a batch process attempts to open the file for writing while another process already has it open for writing. The two processes could be on the same machine, or they could be on different machines if your are dealing with a file on a shared network drive. Both processes could be batch process, but they don't have to be.

It is possible to safely write to a log file "simultaneously" from multiple batch processes with a little bit of code to manage the locking of the file. See How do you have shared log files under Windows?

Community
  • 1
  • 1
dbenham
  • 127,446
  • 28
  • 251
  • 390