[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Not able to read a file just created

Naresh Ramaswamy

2/27/2009 11:55:00 AM

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
--
Posted via http://www.ruby-....

3 Answers

Choi, Junegunn

2/27/2009 12:17:00 PM

0

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.


--
junegunn.

Louis-Philippe

2/27/2009 3:38:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

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 <jg@samdorr.net>

> 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.
>
>
> --
> junegunn.
>
>

Naresh Ramaswamy

3/3/2009 7:25:00 AM

0

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

--
Posted via http://www.ruby-....