Unbufferred output in bash shell
Hi, when I redirect the output of a program to a file, e.g. myprog > file.txt, the shell seems to buffer the output before writing to the file. From my observation on my machine, the buffer seems to be 4K. Is there a way to let bash immediately write any output strings to file (not using buffer at all)? TIA. -- Regards, Verdi -- GMX DSL = Maximale Leistung zum minimalen Preis! 2000 MB nur 2,99, Flatrate ab 4,99 Euro/Monat: http://www.gmx.net/de/go/dsl
Verdi, On Tuesday 30 August 2005 22:26, Verdi March wrote:
BASH is not involved in buffering the output of processes it spawns (*). The program itself (its use of standard I/O libraries and / or system calls, etc.) determines whether or how much buffering is performed or when the output buffer is flushed. It cannot be controlled from the shell, BASH or otherwise. The classic C stdio library, e.g., alters its buffering behavior based on the kind of output destination, mostly whether it's a tty or some other kind of file. (*) The only exception is for commands that are built into the shell itself (there are many).
Randall Schulz
Hi, Randall R Schulz wrote:
I see. So how do I controlled the behaviour? The program was created by me, and I used printf("...\n"); to produce the output. If stdout is the terminal, every '\n' will force the whole string to be printed. I need this behaviour too when redirecting to a file. Is it possible? -- Regards, Verdi -- Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko! Satte Provisionen f�r GMX Partner: http://www.gmx.net/de/go/partner
On Aug 31, 05 09:39:14 +0200, Verdi March wrote:
man setvbuf CU Matthias -- Matthias Hopf <mhopf@suse.de> __ __ __ Maxfeldstr. 5 / 90409 Nuernberg (_ | | (_ |__ mat@mshopf.de Phone +49-911-74053-715 __) |_| __) |__ labs www.mshopf.de
Matthias Hopf wrote:
man setvbuf
This looks like what I need. Thanks. -- Regards, Verdi -- 5 GB Mailbox, 50 FreeSMS http://www.gmx.net/de/go/promail +++ GMX - die erste Adresse f�r Mail, Message, More +++
participants (3)
-
Matthias Hopf
-
Randall R Schulz
-
Verdi March