| delorie.com/archives/browse.cgi | search |
| X-Recipient: | archive-cygwin AT delorie DOT com |
| DKIM-Filter: | OpenDKIM Filter v2.11.0 sourceware.org A8136386F809 |
| DKIM-Signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; |
| s=default; t=1595954360; | |
| bh=ds/qo71CcMIRf+E+88GkVv9C+zW4BwEJHbHrv78rYTw=; | |
| h=Date:To:Subject:In-Reply-To:References:List-Id:List-Unsubscribe: | |
| List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: | |
| From; | |
| b=SH9iJkEYqLYULztTjw54mHofPRoVb8PNaidu7rYImdniIYuZhwVHazLnDr5HOsXIx | |
| 56qpCeYAfdiBHUWIUA376Qalgk3rb0Pk5cNv2xYGh1BOnwClHDbM1XKmcV21pl7HIe | |
| BBPJjiUgENUQbOa3NAOFBdKzkUW9ybrChbWPucnc= | |
| X-Original-To: | cygwin AT cygwin DOT com |
| Delivered-To: | cygwin AT cygwin DOT com |
| DMARC-Filter: | OpenDMARC Filter v1.3.2 sourceware.org E5CF63857C5A |
| DKIM-Filter: | OpenDKIM Filter v2.10.3 conssluserg-05.nifty.com 06SGcfZR023657 |
| X-Nifty-SrcIP: | [124.155.38.192] |
| Date: | Wed, 29 Jul 2020 01:38:48 +0900 |
| To: | cygwin AT cygwin DOT com |
| Subject: | Re: stty -cooked not usable since cygwin-3.1.1-1 |
| Message-Id: | <20200729013848.cf6d4d99464e92d92d346029@nifty.ne.jp> |
| In-Reply-To: | <1ea4e90c-7075-39e8-a518-40bc764a5237@bahnhof.se> |
| 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> | |
| X-Mailer: | Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) |
| Mime-Version: | 1.0 |
| X-Spam-Status: | No, score=-0.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, |
| DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_NUMSUBJECT, | |
| RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, | |
| 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 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> | |
| From: | Takashi Yano via Cygwin <cygwin AT cygwin DOT com> |
| Reply-To: | Takashi Yano <takashi DOT yano AT nifty DOT ne DOT jp> |
| Errors-To: | cygwin-bounces AT cygwin DOT com |
| Sender: | "Cygwin" <cygwin-bounces AT cygwin DOT com> |
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.
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;
}
--
Takashi Yano <takashi DOT yano AT nifty DOT ne DOT jp>
--
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
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |