This is the mail archive of the
cygwin
mailing list for the Cygwin project.
RE: Buffering problem in netcat server script
- From: Adam Dinwoodie <Adam dot Dinwoodie at metaswitch dot com>
- To: "cygwin at cygwin dot com" <cygwin at cygwin dot com>
- Date: Tue, 11 Sep 2012 12:34:28 +0000
- Subject: RE: Buffering problem in netcat server script
- Deferred-delivery: Tue, 11 Sep 2012 12:34:00 +0000
- References: <504F2C0B.8050306@hima.com>
Sven Severus wrote:
> Question 1:
> Why do I face different behaviour with "cat -n" and "sed s/e/E/g"?
> Are there cygwin related reasons?
> Which behaviour should I expect (I know there are buffering
> mechanisms for stdout when not connected to a tty, so I tend to
> say the buffering behaviour ist the one to expect).
>
> Question 2:
> What can I do to turn off the buffering behaviour and to get the
> output lines immediately?
> Or is my server script approach inappropriate? What should work
> better?
From `mad sed`:
-u, --unbuffered
load minimal amounts of data from the input files and flush the output
buffers more often
If you add the -u option, sed will buffer less and write to the pipe more
often. I would guess this isn't the default as it's less efficient, but
haven't done anything to verify that.
I believe `cat` never buffers, but I base this on nothing but instinct.
A quick experiment on my handy RHEL box implies this is not Cygwin specific;
the following command shows buffering behaviour too:
tail -f tmpfile | sed 's/e/E/g' | tee outfile
(I'm using the pipelines so I can see what's going on without sed thinking
stdin or stdout are a terminal.)
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple