On Fri, 14 Mar 2003 09:35:55 +0200 shlomo solomon <[EMAIL PROTECTED]> wrote: > So what's my problem? It seems that both the above solutions are writing to a > buffer and the actual screen output is not immediate, but in spurts.
That's a result of stdio default behaviour. Each application can control its buffering behaviour via setvbuf(3) to one of three possible modes: - Unbuffered: every call to stdio (printf, puts, putchar, etc.) is passed to write(2). - Fully buffered: Only when a buffer (programmer specified size) is filled, write(2) is called. - Line buffered: If a linefeed character is written (or buffer is full), write(2) is called. The defaults are: - STDERR: unbuffered - STDOUT: line buffered if it's connected to tty device, fully buffered otherwise. So, by default, if you pipe the output (or redirect it to a file) the output from STDOUT will be fully buffered. If your script is written in perl, than look in perldoc perlvar for the special variable $| (dollar-pipe), it would give you partial control over your output buffering. There isn't any such control mechanism for the shell (maybe bash has some extra feature -- anybody?). This won't help you with grep, or any other precompiled application, which raises an interesting question -- Maybe we need a general mechanism to control this default behaviour (when the application itself does not specify the buffering). Since this is done in stdio library the obvious solution would be via some new environment variable. E.g: env "STDIO_BUFFER=all:buffered,1=unbuffered" foo | bar | geek Cheers, ---------------------------------------------------------------- Oron Peled Voice/Fax: +972-4-8228492 [EMAIL PROTECTED] http://www.actcom.co.il/~oron "It's almost like we're doing Windows users a favor by charging them money for something they could get for free, because they get confused otherwise." - Larry Wall. ================================================================= To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]