How to read a file that is always written to?
-
Hello everyone! My first post here :) As you might have guessed from the message title: is it possible to read from a text file, while another application is always writing to it, without disturbing the writing process? And if it is, how do I do it? I'd like to create an application that open such a file, and gets the data that has been added to the file since my last read (maybe you've got some good suggestions how to do that?). Thanks in advance, Paul
-
Hello everyone! My first post here :) As you might have guessed from the message title: is it possible to read from a text file, while another application is always writing to it, without disturbing the writing process? And if it is, how do I do it? I'd like to create an application that open such a file, and gets the data that has been added to the file since my last read (maybe you've got some good suggestions how to do that?). Thanks in advance, Paul
It might be possible to read from the file, but it's hard to guarantee that it would never disturb the writing process. It sounds like you should use something that has much better functionality to handle multiple users, like a database. --- b { font-weight: normal; }
-
Hello everyone! My first post here :) As you might have guessed from the message title: is it possible to read from a text file, while another application is always writing to it, without disturbing the writing process? And if it is, how do I do it? I'd like to create an application that open such a file, and gets the data that has been added to the file since my last read (maybe you've got some good suggestions how to do that?). Thanks in advance, Paul
-
It might be possible to read from the file, but it's hard to guarantee that it would never disturb the writing process. It sounds like you should use something that has much better functionality to handle multiple users, like a database. --- b { font-weight: normal; }
That is true, but my question was more out of curiosity after observing programs like AviPreview or VLAN play avi or mpg files while they were still being downloaded. I hope someone knows a solution because this is driving me nuts :wtf:
-
i looked at that, but it waits until the writing process is complete and then opens the file and reads the changes. i'd like to know how to read a file that is being written to while it happens. Or, probably the same, an application that is writing to the file sporadically but never closes the file handle while it is running. thank you for your reply though, i'll get there! maybe this is good material for an article: Advanced File I/O :rolleyes:
-
i looked at that, but it waits until the writing process is complete and then opens the file and reads the changes. i'd like to know how to read a file that is being written to while it happens. Or, probably the same, an application that is writing to the file sporadically but never closes the file handle while it is running. thank you for your reply though, i'll get there! maybe this is good material for an article: Advanced File I/O :rolleyes:
I'm not sure how helpful this is, but I accidentally did something like that a while back. I wrote a program that was supposed to start capturing the screen into a WMV. I made the mistake of telling it to start capturing when it lost focus, as well as play the captured file when I manually stopped it. The result was this: - captured WMV (wrote file) - played WMV in MediaPlayer - program lost focus - program started writing to same WMV just before MP started playing it - I saw the multiple smaller-and-smaller time-delayed MediaPlayer windows in the video. Basically, MediaPlayer was reading a file that was being written just a little ahead of it, so I know it's POSSIBLE. It's just a matter of fooling Windows into doing it intentionally. -Daniel
-
I'm not sure how helpful this is, but I accidentally did something like that a while back. I wrote a program that was supposed to start capturing the screen into a WMV. I made the mistake of telling it to start capturing when it lost focus, as well as play the captured file when I manually stopped it. The result was this: - captured WMV (wrote file) - played WMV in MediaPlayer - program lost focus - program started writing to same WMV just before MP started playing it - I saw the multiple smaller-and-smaller time-delayed MediaPlayer windows in the video. Basically, MediaPlayer was reading a file that was being written just a little ahead of it, so I know it's POSSIBLE. It's just a matter of fooling Windows into doing it intentionally. -Daniel
That's exactly what i mean! Funny though, because I never caught WMP doing anything like that (it refuses to play avi's or mpg's while the download is still in progress). Maybe it's because WMV's are designed with streaming in mind, so WMP opens it differently than avi's or mpg's.. Paul
-
That's exactly what i mean! Funny though, because I never caught WMP doing anything like that (it refuses to play avi's or mpg's while the download is still in progress). Maybe it's because WMV's are designed with streaming in mind, so WMP opens it differently than avi's or mpg's.. Paul
I'm not very knowledgeable about streaming or deep file IO junk, but it would make sense for WMP to check to see if the file is not currently being written to. In my scenario, I wouldn't be surprised if my program hadn't quite started writing to the file when WMP checked it (the WMV was a distinct file from a previous start-stop capture), kind of like how people used to play copied PS games (I never did, but I heard how to do it, with a real disk when the PS does its little preliminary validity check, then swapping). -Daniel
-
That is true, but my question was more out of curiosity after observing programs like AviPreview or VLAN play avi or mpg files while they were still being downloaded. I hope someone knows a solution because this is driving me nuts :wtf:
pistolenpaultje wrote:
AviPreview or VLAN play avi or mpg files while they were still being downloaded
I don't know about these programs but it looks like LimeWire just pauses the download while it writes the downloaded bits so far to a temporary file which it then displays. Maybe these programs do the same and you havn't realised.
You know you're a Land Rover owner when the best route from point A to point B is through the mud. Ed
-
Hello everyone! My first post here :) As you might have guessed from the message title: is it possible to read from a text file, while another application is always writing to it, without disturbing the writing process? And if it is, how do I do it? I'd like to create an application that open such a file, and gets the data that has been added to the file since my last read (maybe you've got some good suggestions how to do that?). Thanks in advance, Paul
-
you just have to keep tracks of the position of the writing process and limit yourself to not read beyond where the last write position was.
sounds like just what i need! however i already tried something like that but couldn't get it to work. do you have any suggestion (maybe an article link or code snippet) how i could accomplish that? many thanks for your reply, i now have an idea in what direction to search!:cool: