![]() |
![]() |
#1 |
Random Account
Aug 2009
U.S.A.
179110 Posts |
![]()
I have written a batch file to assist a local mom-and-pop shop automate a data gathering process. It goes as below:
Code:
@echo off :Top cls if not exist c:\data\inventory.bat goto wait move c:\data\inventory.bat c:\temp\inventory.bat call c:\temp\inventory.bat :wait timeout 1800 goto top He's my question: What happens if the 'move' command happens at the same instant that the original batch file is open for a write operation? I suspect this would raise some sort of error. I know a tiny bit about 'errorlevel' statements. This one, I am not sure how to handle. |
![]() |
![]() |
![]() |
#2 | |
If I May
"Chris Halsall"
Sep 2002
Barbados
222728 Posts |
![]() Quote:
To avoid race conditions, it's a good idea to wait for a period of time after moving a file which might have writers before doing any work on the file (such as compressing it). Or, even better, make system calls to determine how many write locks are on the file. |
|
![]() |
![]() |
![]() |
#3 |
Jun 2005
USA, IL
193 Posts |
![]()
If the file is locked, the move command will give you an error indicating, "The process cannot access the file because it is being used by another process" and indicate that zero files were moved. You would need to test if the indicated 'write operation' locks the file or not. For example Excel locks a spreadsheet file when opening, but Notepad doesn't lock a text file when opening.
|
![]() |
![]() |
![]() |
#4 |
Random Account
Aug 2009
U.S.A.
32×199 Posts |
![]()
I made a modification. Not sure if it will work or not.
Code:
@echo off :Top cls if not exist c:\data\inventory.bat goto wait move c:\data\inventory.bat c:\temp\inventory.bat if not errorlevel 0 goto wait call c:\temp\inventory.bat :wait timeout 1800 goto top |
![]() |
![]() |
![]() |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Batch jobs using AWS Batch | GP2 | Cloud Computing | 1 | 2016-12-07 11:31 |
14e batch of WU's | pinhodecarlos | NFS@Home | 25 | 2015-07-25 17:50 |
Got first batch of TF to 75 | Chuck | GPU to 72 | 23 | 2015-05-10 20:34 |
Windows batch file for NFS - any help? | f1pokerspeed | Programming | 9 | 2013-12-24 18:21 |
batch file | em99010pepe | No Prime Left Behind | 7 | 2008-03-15 10:53 |