Forum: Ruby Not able to read a file just created

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Naresh R. (Guest)
on 2009-02-27 13:56
hi,

My Ruby code is as follows
In a class
One method creats and writes (write_data) one/more files by reading data
from another file.
Another method reads (read_data) these files and perform some action.

Observed that I am not able to read contents of files just created
(though I can see data in those files as expected) when I call these
functions one after the other.

Where as if I run only the 'Read' method I am able to read the files.
There seems to be no error in the code, but I feel that since the file
is just getting created it is not allowing me to do any action on that
unless my program is closed and  a new program started.

Is there any solution for this? Attached the code for your view.

Naresh
Choi, Junegunn (Guest)
on 2009-02-27 14:17
(Received via mailing list)
Try calling File#flush method after writing to the newly created file,
so that the buffered data is flushed to OS. Or you can even call
File#fsync to ensure that the data is actually written to disk.
Louis-Philippe (Guest)
on 2009-02-27 17:39
(Received via mailing list)
If these tricks don't do, try closing the writing filehandle before
opening
the reading one, that does it for me.

L-P

2009/2/27 Choi, Junegunn <removed_email_address@domain.invalid>
Naresh R. (Guest)
on 2009-03-03 09:26
Louis-Philippe wrote:
> If these tricks don't do, try closing the writing filehandle before
> opening
> the reading one, that does it for me.
>


It did work for me too, thanks you very much.

Naresh
This topic is locked and can not be replied to.