Re: Reading a file as it fills up by another program
Re: Reading a file as it fills up by another program
- Subject: Re: Reading a file as it fills up by another program
- From: Christopher Nebel <email@hidden>
- Date: Sat, 13 Dec 2003 01:11:17 -0800
On Dec 12, 2003, at 6:04 AM, Harald E Brandt wrote:
It keeps the file open - it is a redirect (incl stderr) after a pipe.
I just talked to a Unix guru who says that this is a relatively common
problem caused by the fact that Unix usually buffers everything before
it is actually written to file. That means I am stuck!
Well, stuck-ish. Your guru is at least partly correct -- the answers
you get depend on just how often you ask and how the output from the
original source is buffered. By default, stdout is block buffered,
where a "block" is usually a few kbytes, so if you're watching stdout,
you won't get new data that often. stderr is normally line buffered,
so you get new data every time there's a new line. For example:
~/test:
#!/usr/bin/perl
for ( 1 .. 100 ) { print "$_\n"; sleep(1); }
do shell script "~/test > f 2>&1 &"
repeat
display dialog (do shell script "tail -n 1 f")
end repeat
You'll just get lots of blank dialogs for most of the script. (Block
buffering in action.) If you change the Perl script to say 'print
STDERR "$_\n"', you'll get increasing numbers in the dialog. I find it
somewhat surprising that curl is writing its progress information to
anything other than stderr, but hey, I didn't write it. The tech note
admittedly glosses over this point -- it assumes that you're getting
largish amounts of data, and that you're trying to process the whole
file, so block buffering won't be a big deal.
--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.