Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a normal batch file, running on XP. First, program A apends data (a string) to the end of file X.dll (on the server). Then program B opens the file, and looks for the data. However, sometimes (usually), program B is evidently reading a version of the file before the string has been appended, despite the fact that it is being sequentially carried out after program A has returned.

If we call dir X.dll between A and B, then B reads the altered file correctly.

The same batchfile, running on a Windows 7 machine on the same network, works flawlessly.

Does anyone have any ideas what on earth is going on?

share|improve this question
    
Question also posted on Server Fault - serverfault.com/questions/171332/… –  ChrisF Aug 17 '10 at 13:10
    
Is it possible that the file system is delaying the writing of the file to disk (performance)? –  w3d Aug 17 '10 at 16:53
    
That's what I'd like to know.. and if so, what to do about it. –  Joel in Gö Aug 18 '10 at 12:07
add comment

1 Answer

It looks like B is running before A is finished. One way to avoid this is to use START. Run A with this command: start /wait a. The batch file will not continue until A is finished running.

share|improve this answer
    
Idea is ok, but not in this case; we are running the program without "start", which has the same effect as " start /wait". Program A also outputs "finished" when it is finished, and we output "B starting" before starting B, so we can see that A is really finished before B starts. –  Joel in Gö Aug 18 '10 at 14:03
    
@Joel: If write caching is enabled on the drive containing the data file, that might be a factor. Disabling write caching will hurt performance, but it might be worth trying to rule it out. Right-click the drive in Explorer, Properties, Hardware tab, select the drive and click Properties. To make sure you have the right drive, go to the Volumes tab and click Populate. Go to the Policies tab and disable write caching. You might have to reboot. Re-run your test. If that works, we're looking for a way to flush the write cache on the fly from within a batch file. –  boot13 Aug 18 '10 at 14:17
    
It is a network drive, and almost certainly has write caching. (The properties window does not show Hardware). I agree, that is probably the problem; as said above, doing "dir filename" between the program calls works. –  Joel in Gö Aug 18 '10 at 14:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.