X-Recipient: archive-cygwin AT delorie DOT 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 To: "cygwin AT cygwin DOT 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: References: <504F2C0B DOT 8050306 AT hima DOT 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 AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT 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