Re: reading a text files as a UNIX command writes to it
Re: reading a text files as a UNIX command writes to it
- Subject: Re: reading a text files as a UNIX command writes to it
- From: Christopher Nebel <email@hidden>
- Date: Tue, 1 Jun 2004 15:21:46 -0700
On Jun 1, 2004, at 1:42 PM, Richard Covert wrote:
One of the nice things about UNIX is the 'tail -f <file>' command.
... I would like to capture these lines as they appear in the ... file
and send them to a 'text view of scroll view' object in my window
'main'.
So, the problem is that I would have do an idle loop and read the
output file every 30 seconds or so, until
I get a line that I know is the last line (lineXX if I know what XX is
in advance).
But, this approach has a couple of problems. First, it blocks the
current AS script. Second, it uses valuable CPU cycles.
Uh, what do you think tail(1) is doing? OK, on sufficiently smart
OSes, it actually uses kqueue notifications, but if they're not
available, it just sits in a loop, waking up every quarter-second to
print out any more characters that have shown up.
An periodic idle handler shouldn't block anything, and if your idle
time is one second or more, you won't be using that much CPU. One
trick to be aware of: an open file (as in, opened using "open for
access" will maintain its read position until you close it. You can
open the file, read until you hit the end, and every second (or
whatever) try reading again without specifying a new position -- if
there's more data, you'll get it.
--Chris Nebel
AppleScript Engineering
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.