Portal Home > Knowledgebase > Articles Database > LINUX BASH : keep the order in STD* output tunnels


LINUX BASH : keep the order in STD* output tunnels




Posted by Mister Bark, 10-31-2012, 11:17 AM
Hi! This will make a file "test" : ... and not : Why and how make sure to keep the order of all STD*? (I guess it's related to the buffers, that are probably separated for each output) Please note that my question concerns bash, not perl (that program is just a test) THANKS!

Posted by FINESEC, 10-31-2012, 11:59 AM
Turn autoflashing on: perl -e '$| = 1; print("a\n"); sleep(2); warn("WARN\n"); print("b\n");' >> test 2>&1

Posted by Mister Bark, 10-31-2012, 12:01 PM
I know, thanks. But as I said : "Please note that my question concerns bash, not perl (that program is just a test)" And that problem is related to bash because if you execute my perl test without redirecting to a file, it is in order in the terminal. Last edited by Mister Bark; 10-31-2012 at 12:06 PM.

Posted by FINESEC, 10-31-2012, 12:16 PM
Sorry, I didn't read the last line ;-) It's not possible in bash afaik. You might try using stderr only or give this tool http://expect.sourceforge.net/example/unbuffer.man.html a try.

Posted by Mister Bark, 10-31-2012, 12:44 PM
ah, that's interesting thanks But I cannot find the program on the net nor in my distribs!

Posted by FINESEC, 10-31-2012, 01:31 PM
Hmm, try this one: http://man7.org/tlpi/code/online/dis...nbuffer.c.html

Posted by Mister Bark, 10-31-2012, 03:00 PM
thanks! I may look a bit stupid but... I've compiled many programs from source (configure and other stuff) but not from a single c file... how am I supposed to build that?

Posted by FINESEC, 10-31-2012, 03:19 PM
Download and put all files to the same directory: http://man7.org/tlpi/code/online/dis...nbuffer.c.html http://man7.org/tlpi/code/online/dis...ty_fork.h.html http://man7.org/tlpi/code/online/dis...ty_fork.c.html http://man7.org/tlpi/code/online/dis...nctions.h.html http://man7.org/tlpi/code/online/dis...nctions.c.html http://man7.org/tlpi/code/online/dis...lpi_hdr.h.html compile project using this command: gcc *.c Lemme know if that doesn't work.

Posted by FINESEC, 10-31-2012, 03:44 PM
http://finesec.com/files/unbuffer.tar.gz <- all files are in this package

Posted by Mister Bark, 10-31-2012, 05:39 PM
hehe thanks AWESOME

Posted by MattF, 11-01-2012, 04:00 AM
It isnt bash nor perl When using stdio stderr isnt buffered, stdout is buffered how so is depending on what its talking to, if its a file or pipe then its block buffered, if its a tty i.e. is_atty(fd) then its line buffered. This can be manipulated to some extent but a generally a concern that outputting app shouldnt do. I suspect unbuffer is injecting it own LD_PRELOAD so its doesnt do buffering, Im going to explore more... Loads of docs out there on stdio buffer that explain stuff better and more thoroughly

Posted by Mister Bark, 11-01-2012, 09:14 AM
thanks for the explanation



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
message headers and IP (Views: 652)
VPS SSD or Not (Views: 692)
Error 403 (Views: 744)
LDAP, PHP and IIS7 (Views: 700)


Language: