Mail Archives: cygwin/2020/07/31/02:53:23
X-Recipient: | archive-cygwin AT delorie DOT com
|
X-Original-To: | cygwin AT cygwin DOT com
|
Delivered-To: | cygwin AT cygwin DOT com
|
DMARC-Filter: | OpenDMARC Filter v1.3.2 sourceware.org 16FED385700D
|
Authentication-Results: | sourceware.org;
|
| dmarc=none (p=none dis=none) header.from=bahnhof.se
|
Authentication-Results: | sourceware.org; spf=pass smtp.mailfrom=rabbe AT bahnhof DOT se
|
X-Virus-Scanned: | Debian amavisd-new at bahnhof.se
|
X-Spam-Score: | -2.711
|
X-Spam-Level: | |
X-Spam-Status: | No, score=-0.6 required=5.0 tests=BAYES_00, BODY_8BITS,
|
| KAM_DMARC_STATUS, KAM_NUMSUBJECT, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS,
|
| TXREP autolearn=ham autolearn_force=no version=3.4.2
|
Subject: | Re: Re: stty -cooked not usable since cygwin-3.1.1-1
|
To: | cygwin AT cygwin DOT com
|
References: | <ad285b65-fed9-e6e5-eb3f-432fadc95daf AT bahnhof DOT se>
|
| <20200113200152 DOT 5243a304d481677c61c12450 AT nifty DOT ne DOT jp>
|
| <12d7cb6e-b900-6780-1d1c-80ed84cc82d5 AT bahnhof DOT se>
|
| <1ea4e90c-7075-39e8-a518-40bc764a5237 AT bahnhof DOT se>
|
| <20200729013848 DOT cf6d4d99464e92d92d346029 AT nifty DOT ne DOT jp>
|
| <d78149b7-b4c8-5619-71ca-f3b70a04fd26 AT towo DOT net>
|
| <22f2becd-1f2e-5ff8-4999-b34f2fb0bff3 AT bahnhof DOT se>
|
| <f935b0f6-1de3-e2d1-285e-f26cd945985a AT towo DOT net>
|
| <e12b1d54-3037-2b05-77ca-bec1bb3acbf5 AT bahnhof DOT se>
|
From: | Rabbe Fogelholm <rabbe AT bahnhof DOT se>
|
Message-ID: | <57da53a4-db59-f7db-cfd7-62c39c67263c@bahnhof.se>
|
Date: | Fri, 31 Jul 2020 08:52:30 +0200
|
User-Agent: | Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101
|
| Thunderbird/68.10.0
|
MIME-Version: | 1.0
|
In-Reply-To: | <e12b1d54-3037-2b05-77ca-bec1bb3acbf5@bahnhof.se>
|
X-Spam-Checker-Version: | SpamAssassin 3.4.2 (2018-09-13) on
|
| server2.sourceware.org
|
X-BeenThere: | cygwin AT cygwin DOT com
|
X-Mailman-Version: | 2.1.29
|
List-Id: | General Cygwin discussions and problem reports <cygwin.cygwin.com>
|
List-Unsubscribe: | <https://cygwin.com/mailman/options/cygwin>,
|
| <mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
|
List-Archive: | <https://cygwin.com/pipermail/cygwin/>
|
List-Post: | <mailto:cygwin AT cygwin DOT com>
|
List-Help: | <mailto:cygwin-request AT cygwin DOT com?subject=help>
|
List-Subscribe: | <https://cygwin.com/mailman/listinfo/cygwin>,
|
| <mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
|
Errors-To: | cygwin-bounces AT cygwin DOT com
|
Sender: | "Cygwin" <cygwin-bounces AT cygwin DOT com>
|
X-MIME-Autoconverted: | from base64 to 8bit by delorie.com id 06V6r4V0016660
|
On 2020-07-29 22:03, Rabbe Fogelholm wrote:
> On 2020-07-29 01:30, Thomas Wolff wrote:
>>
>>
>> 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 <stdio.h>
>>>>> #include <unistd.h>
>>>>> #include <termios.h>
>>>>> #include <string.h>
>>>>> #include <pthread.h>
>>>>> #include <sys/wait.h>
>>>>>
>>>>> 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
>
> Hi Thomas, this small program can be used for experiments:
>
> --- ReadKeystrokes.java ------------
>
> import java.io.IOException;
>
> public final class ReadKeystrokes {
>
> Â Â Â Â /**
> Â Â Â Â * Read keystrokes and write codes to standard output. The
> Â Â Â Â Â Â Â Â * intention is that writing should occur immediately.
> Â Â Â Â * @param args
> Â Â Â Â * @throws InterruptedException
> Â Â Â Â * @throws IOException
> Â Â Â Â */
> Â Â Â Â public static void main(String[] args) throws IOException,
> InterruptedException {
> Â Â Â Â Â Â Â System.out.println("Press any keys; to exit press 'q'");
>
> Â Â Â Â Â Â Â for (; true;) {
> Â Â Â Â Â Â Â Â Â Â Â if (System.in.available() > 0) {
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â final int c = System.in.read();
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â System.out.println(String.format("key was pressed,
> code: %d", c));
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (c == 'q') {
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â break;
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â }
> Â Â Â Â Â Â Â Â Â Â Â }
> Â Â Â Â Â Â Â Â Â Â Â else {
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Thread.sleep(100);
> Â Â Â Â Â Â Â Â Â Â Â }
> Â Â Â Â Â Â Â }
> Â Â Â Â }
> }
>
> ------------------------------------
>
> After compiling, assuming ReadKeystrokes.class is in the current
> directory, launch it with:
>
> java -classpath ./ ReadKeystrokes
>
>
I suppose the behavior of the above test program may depend on the Java
runtime being used. I am using Oracle Java SE 1.8, version 202.
--
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
- Raw text -