Re: flush() bug?
- Posted by ChrisBurch2 <crylex at freeuk.co.uk> Sep 22, 2005
- 455 views
Andy Serpa wrote: > > Using the following program with exw.exe: > > > ----------------------------- > include file.e > include get.e > > integer fn > > fn = open("test.txt","w") > puts(fn,"Hello") > close(fn) > > ? gets(0) > > > ------------- > fn = open("test.txt","w") > puts(fn,"Hello") > flush(fn) > close(fn) > > ------------- Carraige return after close(fn)? > > It also works the same way, as expected. > > However, if we do this: > > -------------- > fn = open("test.txt","w") > puts(fn,"Hello") > flush(fn) > puts(fn,"Hello") > close(fn) > -------------- No carraige return ater close(fn) > > The file test.txt now stays locked even though it has been closed -- it won't > release > until we terminate the program. In other words, if we use flush() at any > point, and > then write data to the file after the flush() and then close(), the file stays > locked. > > The fix: > > -------------- > > fn = open("test.txt","w") > puts(fn,"Hello") > flush(fn) > puts(fn,"Hello") > flush(fn) > close(fn) > > -------------- Carraige return after close(fn)? > > We have to add an extra flush() before the close() to get it to release. An > easy fix, > but still the behavior is not correct unless I'm missing something... > Just a thought. Last line in a file (script / interpreted) often needs a carraige return to be read correctly. I often had this problem when compiling C programs. Chris