Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 -… – ChrisF Aug 17 '10 at 13:10
Is it possible that the file system is delaying the writing of the file to disk (performance)? – w3dk 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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .