delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2012/09/11/08:18:58

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-0.2 required=5.0 tests=AWL,BAYES_50
X-Spam-Check-By: sourceware.org
X-MDAV-Processed: hima.com, Tue, 11 Sep 2012 14:18:24 +0200
X-Spam-Processed: hima.com, Tue, 11 Sep 2012 14:18:24 +0200 (not processed: message from trusted or authenticated source)
X-MDRemoteIP: 192.168.100.10
X-Return-Path: s DOT severus AT hima DOT com
X-Envelope-From: s DOT severus AT hima DOT com
X-MDaemon-Deliver-To: cygwin AT cygwin DOT com
Message-ID: <504F2C0B.8050306@hima.com>
Date: Tue, 11 Sep 2012 14:18:19 +0200
From: Sven Severus <s DOT severus AT hima DOT com>
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Buffering problem in netcat server script
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Hallo all,

I have a very simple two-line script myserver.sh

#! /bin/sh
tee log1 | cat -n | tee log2

It writes each input line to logfile log 1, modifies it (here simply
by prepending a line number via "cat -n"), writes the modified
line to logfile log2 and outputs it to stdout.
The script is launched by netcat (in listening or server mode),
with stdin and stdout connected to port 8888:
nc -vv -lp 8888 -e myserver.sh

When a connection ist established on port 8888, myserver.sh is
started. All works properly: After sending an input line via
port 8888 I immediately receive the modified output line.
In log1 I can see each input line and in log2 each output line,
just in time. Fine!

Now I modified myserver.sh to get a different modification:
I replaced the "cat -n" part by "sed s/e/E/g" to capitalize
all "e"-characters in the input stream.
Now when a connection ist established I do not receive any output
for the given input lines. In log1 I can see any input line (in
time, as before), but log2 remains empty. Not what I wanted!
But when I continue sending input lines and the amount of input
data exceeds 64kB, then - flupp - I get all the long expected
output (and see it in log2).
It seems obvious, that this behaviour is related to buffering.

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?

Thanks a lot in advance.

Best regards
Sven Severus



-- 
Mit freundlichen Grüßen

Dipl. Inform. Sven Severus
Softwareentwicklung
----------------------------------------------------------
HIMA Paul Hildebrandt GmbH + CO KG
Abt: Entwicklung Software
Albert-Bassermann-Strasse 28
68782 Bruehl
Germany

Tel: +49 6202 709-289
Fax: +49 6202 709-299
E-Mail: s DOT severus AT hima DOT com
Internet: www.hima.de


-- 
HIMA Paul Hildebrandt GmbH + Co KG, Albert-Bassermann-Str. 28, 68782 Bruehl bei Mannheim
Kommanditgesellschaft, Sitz Bruehl, Deutschland - Registergericht Mannheim HRA 421017
Ust-ID: DE 144286400, St.Nr: 43038 00190

Persoenlich haftende Gesellschafterin Paul Hildebrandt Verwaltungsgesellschaft mbH,
Sitz Bruehl, Deutschland - Registergericht Mannheim HRB 420588

Geschaeftsfuehrer: Dipl.-Betriebswirt Steffen Philipp


--
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019