[Pharo-project] tail-like
Hi, I am looking for a way to implement a logic like in the linux tail command: watch a file and react whenever a new line appears at the end of that file. Can anyone point me to some resources that I might use for something like this? Cheers, Doru -- www.tudorgirba.com "When people care, great things can happen."
On 5 April 2012 22:07, Tudor Girba <tudor@tudorgirba.com> wrote:
Hi,
I am looking for a way to implement a logic like in the linux tail command: watch a file and react whenever a new line appears at the end of that file.
Can anyone point me to some resources that I might use for something like this?
well, best would be the source code of tail command itself. it opens a file for reading and then polls periodically for more data. but i don't know details
Cheers, Doru
-- www.tudorgirba.com
"When people care, great things can happen."
-- Best regards, Igor Stasenko.
It kind of depends on the OS, but all of them let you subscribe to events on the files in some way. So you would subscribe with os to notify you when some file is changed in some way, keep some internal house keeping information like position up to which you have displayed info, verify that file has indeed changed, read and display new stuff, update internal info. In essence nothing substantially complicated, but windows and unix interface differs, and at least windows (never investigated unix api in more detail) requires you to dance a bit before you get some results. Such pieces of code is also often used by text editors to notify user that the file in editor has been changed from the outside. (maybe moose already has something like that?) Davorin Rusevljan http://www.cloud208.com/ ----- http://www.cloud208.com/ -- View this message in context: http://forum.world.st/tail-like-tp4535899p4537087.html Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
On Fri, Apr 06, 2012 at 03:21:33AM -0700, drush66 wrote:
It kind of depends on the OS, but all of them let you subscribe to events on the files in some way. So you would subscribe with os to notify you when some file is changed in some way, keep some internal house keeping information like position up to which you have displayed info, verify that file has indeed changed, read and display new stuff, update internal info.
In essence nothing substantially complicated, but windows and unix interface differs, and at least windows (never investigated unix api in more detail) requires you to dance a bit before you get some results.
Such pieces of code is also often used by text editors to notify user that the file in editor has been changed from the outside. (maybe moose already has something like that?)
Davorin Rusevljan
On unix/linux/osx you can probably do this with AioPlugin. The OSProcess unit tests provide examples in AioEventHandlerTestCase. The example in AioEventHandlerTestCase>>testFileReadableEvent is a good place to start. Dave
Thanks. I will take a look. Doru On 6 Apr 2012, at 17:32, David T. Lewis wrote:
On Fri, Apr 06, 2012 at 03:21:33AM -0700, drush66 wrote:
It kind of depends on the OS, but all of them let you subscribe to events on the files in some way. So you would subscribe with os to notify you when some file is changed in some way, keep some internal house keeping information like position up to which you have displayed info, verify that file has indeed changed, read and display new stuff, update internal info.
In essence nothing substantially complicated, but windows and unix interface differs, and at least windows (never investigated unix api in more detail) requires you to dance a bit before you get some results.
Such pieces of code is also often used by text editors to notify user that the file in editor has been changed from the outside. (maybe moose already has something like that?)
Davorin Rusevljan
On unix/linux/osx you can probably do this with AioPlugin. The OSProcess unit tests provide examples in AioEventHandlerTestCase. The example in AioEventHandlerTestCase>>testFileReadableEvent is a good place to start.
Dave
-- www.tudorgirba.com "We are all great at making mistakes."
Tudor Girba-2 wrote
Thanks. I will take a look.
I think that dearly missed Dolphin Smalltalk had implementation for Windows, so you could also grab Dolphin Community Edition and take a look how it is implemented there. Davorin Rusevljan http://www.cloud208.com/ ----- http://www.cloud208.com/ -- View this message in context: http://forum.world.st/tail-like-tp4535899p4540784.html Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
Tudor Girba-2 wrote
Thanks. I will take a look.
I think that dearly missed Dolphin Smalltalk had implementation for Windows, so you could also grab Dolphin Community Edition and take a look how it is implemented there. Davorin Rusevljan http://www.cloud208.com/ ----- http://www.cloud208.com/ -- View this message in context: http://forum.world.st/tail-like-tp4535899p4540785.html Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
participants (4)
-
David T. Lewis -
drush66 -
Igor Stasenko -
Tudor Girba