0

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?

3
  • Question also posted on Server Fault - serverfault.com/questions/171332/…
    – ChrisF
    Aug 17, 2010 at 13:10
  • Is it possible that the file system is delaying the writing of the file to disk (performance)?
    – MrWhite
    Aug 17, 2010 at 16:53
  • That's what I'd like to know.. and if so, what to do about it. Aug 18, 2010 at 12:07

1 Answer 1

1

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.

3
  • 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. Aug 18, 2010 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, 2010 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. Aug 18, 2010 at 14:28

You must log in to answer this question.

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