From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.74]) by sourceware.org (Postfix) with ESMTPS id B14503858D35 for ; Tue, 28 Jul 2020 23:30:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B14503858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=towo.net Authentication-Results: sourceware.org; spf=none smtp.mailfrom=towo@towo.net Received: from [192.168.178.45] ([95.90.245.244]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N94uf-1kolOK0xXD-0169hJ for ; Wed, 29 Jul 2020 01:30:47 +0200 Subject: Re: stty -cooked not usable since cygwin-3.1.1-1 To: cygwin@cygwin.com References: <20200113200152.5243a304d481677c61c12450@nifty.ne.jp> <12d7cb6e-b900-6780-1d1c-80ed84cc82d5@bahnhof.se> <1ea4e90c-7075-39e8-a518-40bc764a5237@bahnhof.se> <20200729013848.cf6d4d99464e92d92d346029@nifty.ne.jp> <22f2becd-1f2e-5ff8-4999-b34f2fb0bff3@bahnhof.se> From: Thomas Wolff X-Tagtoolbar-Keys: D20200729013044810 Message-ID: Date: Wed, 29 Jul 2020 01:30:44 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <22f2becd-1f2e-5ff8-4999-b34f2fb0bff3@bahnhof.se> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:q89Lf+n2OY/XQ9TwADUWxRgdusjHwY1eyi8gSPnpgYy+7olKGFR TmMSY6gj2S0RKgh9ook95qtsiPMnfdrix5yR1RqIZRb6jgpPXFRZsDjyb3gj+zMJOkBRGrk 1m0JvxkPx0pjddAUWXRESOCiJDe1HNW7fFRBrZqVHoAUFC/t3bbt3HViZjEJaRls8T2KgXc AO/P2PQIVdjyGTnYCpdSA== X-UI-Out-Filterresults: notjunk:1;V03:K0:klLJwkXsLuQ=:NB+/uLXufS5DcUscHAAvwL 6zVgNg6XwaV4igLVySHG7M+vmZOKV1yWjLdiH74wFwA/BkRrhwN07hJ6PQmHQYpn1yOXzz4Hf JGdKPEB3CNGbIy2+XPkYsvdj/WzGtGrIMJS5o2AHhv7lGpZWS6j5TXfWZN23yfUinbEEuZxWY 8WOwtE3sMdlsbxS3GTBV/BmGwBLxVvWxb5adY9+XY/YjVw72mwm98enfk1u7nL9bUfPrlfPKg zZNm7/qJAZV7WBehGXwxnLoRBoOjS98GcbSb1sKr53fnCup+jT80ZGYS61iQfbu7ukbshndyC n2FDxyINT61koy6FY7hS20WH0f0zqYEltvCx1k9hc/KPQIPatd8ELDPZY3rr8RMllewFV2zVY pHIST+SM5mp+wJFPpy+NIdRAJJX3cmsn8tikDp/PXvcy4KgocJyl9yBDhR50Y91bdxfjJQzQW Dga/8656YMwc5B54B52sD3iWHkpLM29h8Ku/vz87GbZ0UvJnMX48gaNNRI1HCbKMYZE75JZCI AHG187Ftcqpnh2riMvqcKS6QLk6A6DHoiwVh9FjZdBzk+xxo3/Q3H2P6bB6evv8ywNDKV2dlp kATjNaR3ccqRvWor4dGsIk8zeioMaVKD6K6MGV9/GsJrBKPUjUKZS9YHJndGAF7jn3s1n0/i2 tQuCQaD2AHs282S2H/iqdfSKZcJU01W/cC4cEBdHKDLip82scb2/Z6oUDqSPA+bqyxCmlzhBT LWlBuTSq86am/DqLWKYuszSwQYZHxAgV2r/Vnqw2aLUvWOH+7YlwmECT1Rqo2vuyTRxZB6TT1 7A67r6Mfl72bUsS1wtU8mpXeXa8ReiLaHskLEkOqwDj8tZ5Po0VnLwN7kXlkMEKIMX2ewUo X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, BODY_8BITS, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: cygwin@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Jul 2020 23:30:50 -0000 Am 28.07.2020 um 21:51 schrieb Rabbe Fogelholm: > On 2020-07-28 18:56, Thomas Wolff wrote: >> >> >> Am 28.07.2020 um 18:38 schrieb Takashi Yano via Cygwin: >>> On Tue, 28 Jul 2020 15:56:54 +0200 >>> Rabbe Fogelholm wrote: >>>> Rabbe Fogelholm wrote: >>>>> Takashi Yano wrote: >>>>>> On Mon, 13 Jan 2020 11:52:43 +0100 >>>>>> Rabbe Fogelholm wrote: >>>>>>> I am running a console Java program that is started from a >>>>>>> shellscript >>>>>>> wrapper. Before invoking Java the wrapper calls `stty -cooked'. >>>>>>> The Java >>>>>>> program polls the keyboard using System.in.available() and reads >>>>>>> characters immediately using System.in.read(), without waiting >>>>>>> for the >>>>>>> Enter key to be pressed. >>>>>>> >>>>>>> This way of combining `stty -cooked' and Java has stopped >>>>>>> working since >>>>>>> version 3.1.1-1 of the Cygwin package. The Java thread that >>>>>>> reads the >>>>>>> keyboard hangs until Enter is pressed, which is not desirable. >>>>>>> >>>>>>> I had to downgrade to version 3.0.7-1 to resolve the problem. >>>>>>> >>>>>>> Versioning information: >>>>>>> >>>>>>> java version "1.8.0_202" >>>>>>> Java(TM) SE Runtime Environment (build 1.8.0_202-b08) >>>>>>> Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode) >>>>>>> >>>>>>> OS Name: Microsoft Windows 10 Pro >>>>>>> Version: 10.0.17763 Build 17763 >>>>>>> System Type: x64-based PC >>>>>>> >>>>>>> See also the enclosed cygcheck.out. >>>>>>> >>>>>>> To demonstrate the issue I enclose a small Java program that >>>>>>> should be >>>>>>> able to read single keystrokes when `stty -cooked' is in effect. >>>>>> Does your java program work in command prompt? cygwin 3.1.x uses >>>>>> pseudo console, so the native (non cygwin) program works as if it >>>>>> is executed in command prompt. >>>>>> >>>>> With cygwin 3.1.x I can't find a way to make my program work. >>>>> >>>>> When running from within a Cygwin64 terminal the `stty -cooked' >>>>> command >>>>> terminates with exit code 0, but the Java program behaves just as if >>>>> `stty -cooked' is not in effect: It does not handle single keystrokes >>>>> immediately. >>>>> >>>>> When running from a Windows command prompt I can execute the stty >>>>> program as \cygwin64\bin\stty. However, when given the '-cooked' >>>>> argument it complains: >>>>> /usr/bin/stty: 'standard input': unable to perform all requested >>>>> operations >>>>> >>>>> - and here as well the Java program behaves as if `stty -cooked' >>>>> is not >>>>> in effect. >>>> Some time has passed; I am just curious if anyone may have found a >>>> solution to the "stty -cooked" issue. With cygwin-3.0.* it was >>>> possible >>>> to have a Java program act on single keystrokes, with cygwin-3.1 I >>>> don't >>>> know how to do it. Any ideas welcome! >>> Solution 1: >>> Redesign your java program using JNA with kbhit()/getch() instead of >>> System.in.available()/System.in.read(). >>> >>> Solution 2: >>> Add SetConsoleMode() call with ENABLE_LINE_INPUT flag cleared using >>> JNA. >> Couldn't cygwin clear this flag when it sets up ConPTY while the pty >> is in raw mode? >> Thomas >> >>> >>> Solution 3: >>> Use a wrappwer instead of stty such as: >>> >>> #include >>> #include >>> #include >>> #include >>> #include >>> #include >>> >>> void *fwd(void *param) >>> { >>>      FILE *f = (FILE *) param; >>>      char buf[128]; >>>      int len; >>>      while (1) { >>>          if ((len = read(0, buf, sizeof(buf))) <= 0) break; >>>          if (write(fileno(f), buf, len) < len) break; >>>      } >>>      return NULL; >>> } >>> >>> int main(int argc, char *argv[]) >>> { >>>      FILE *f; >>>      int i; >>>      pthread_t th; >>>      struct termios t, t_orig; >>>      char cmd[1024] = {0, }; >>>      if (argc < 2) return 0; >>>      for (i = 1; i < argc && strlen(cmd)+strlen(argv[i]) < >>> sizeof(cmd)-2; i++) { >>>          sprintf(cmd + strlen(cmd), (i>1)?" %s":"%s", argv[i]); >>>      } >>>      f = popen(cmd, "w"); >>>      tcgetattr(0, &t_orig); >>>      t = t_orig; >>>      cfmakeraw(&t); >>>      tcsetattr(0, TCSANOW, &t); >>>      pthread_create(&th, NULL, fwd, f); >>>      wait(NULL); >>>      tcsetattr(0, TCSANOW, &t_orig); >>>      pclose(f); >>>      return 0; >>> } >>> >> >> > Thanks Takashi for suggesting many ways to solve this! The C wrapper > solution looks quite powerful. Can you please provide a full test case, as it worked for you in cygwin 3.0.7, i.e. the Java program and the wrapping commands, for some experiments. Thomas > > Meanwhile it has occurred to me that bash itself can provide a > workaround. Since I start the Java console application from a bash > wrapper already, I have now changed it so that it does something like > this: > > (while true; do read -s -r -N 1 Key; echo "$Key"; done) | java ... > > With these options to 'read' I get action on every keystroke, and the > Java program gets its input as terminated length-1 lines. > -- > Problem reports:      https://cygwin.com/problems.html > FAQ:                  https://cygwin.com/faq/ > Documentation:        https://cygwin.com/docs.html > Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple