X-Recipient: archive-cygwin@delorie.com
X-SWARE-Spam-Status: No, hits=-2.3 required=5.0	tests=AWL,BAYES_00,KHOP_THREADED,RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
From: Adam Dinwoodie <Adam.Dinwoodie@metaswitch.com>
To: "cygwin@cygwin.com" <cygwin@cygwin.com>
Subject: RE: Buffering problem in netcat server script
Date: Tue, 11 Sep 2012 12:34:28 +0000
Deferred-Delivery: Tue, 11 Sep 2012 12:34:00 +0000
Message-ID: <CE9C056E12502146A72FD81290379E9A5B9AAB1B@ENFIRHMBX1.datcon.co.uk>
References: <504F2C0B.8050306@hima.com>
In-Reply-To: <504F2C0B.8050306@hima.com>
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id q8BCaonY027685

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


