From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26196 invoked by alias); 11 Sep 2012 12:18:43 -0000 Received: (qmail 26178 invoked by uid 22791); 11 Sep 2012 12:18:39 -0000 X-SWARE-Spam-Status: No, hits=-0.2 required=5.0 tests=AWL,BAYES_50 X-Spam-Check-By: sourceware.org Received: from kbw.hima.com (HELO hima.com) (217.8.61.133) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 11 Sep 2012 12:18:26 +0000 X-MDAV-Processed: hima.com, Tue, 11 Sep 2012 14:18:24 +0200 Received: from [192.168.3.138] by hima.com (MDaemon PRO v12.5.6) with ESMTP id md50006451768.msg for ; 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.severus@hima.com X-Envelope-From: s.severus@hima.com X-MDaemon-Deliver-To: cygwin@cygwin.com Message-ID: <504F2C0B.8050306@hima.com> Date: Tue, 11 Sep 2012 12:36:00 -0000 From: Sven Severus User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: cygwin@cygwin.com Subject: Buffering problem in netcat server script Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 8bit Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2012-09/txt/msg00139.txt.bz2 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.severus@hima.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