Subject: Re: [Bug] No Keyboard input when using interactive commands with stdin via pipes
From: Takashi Yano via Cygwin <[email-masked]>
To: [email-masked]
Cc: Wladislav Artsimovich <[email-masked]>
Date: Fri, 14 Apr 2023 12:21:15 +0900
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>

On Tue, 11 Apr 2023 08:22:25 +0000
Wladislav Artsimovich wrote:
> Dear Cygwin users,
>  
> there appears to be a bug or a missing implementation detail in either unix pipes or ConPTY, which prevents interactive console programs from receiving keyboard input, when they get stdin via a pipe.
> This report concerns the following Github issue, originally started in the MinTTY Terminal emulator Repo: https://github.com/mintty/mintty/issues/1210
>  
> There are multiple programs, which fail to receive any kind of keyboard input when used in MinTTY and when their stdin input is supplied via a pipe.
> This has been reported multiple times in the MinTTY repo already.
>  
> Examples include: 
>  - `fzf`, which works normally when being called, but stops working properly if it receives a file list via a pipe. Eg.: `fzf` by itself works fine. but `find . | fzf` fails.
>  - By extension, the zsh plugin fzf-plugin fails for the same reason, when opening the command history
>  - The program fx ( https://github.com/antonmedv/fx ) which successfully receives keyboard input for navigating a json file, Eg.: `curl -s https://api.openai.com/v1/chat/completions -H 'Content-Type: application/json' > test.json; fx test.json` but fails when getting the json data as a direct pipe: `curl -s https://api.openai.com/v1/chat/completions -H 'Content-Type: application/json' | fx`
>  
> This happens with MinTTY accessing the MSYS2 environment on Windows. Interestingly enough, this does not happen with Alacritty accessing the MSYS2 environment on Windows. With Alacritty everything is fine, which made me initially suspect MinTTY as being the culprit. However, the MinTTY repo lead diagnosed this issue to come from Cygwin, which is why I write report the bug in this mailing list.
>  
> Is there something that can be done about this? Can I provide additional debug info or logs to help fix this?

Thnaks for the report.

I cound reproduce your problem by:
$ yes | cat -n | more.com
(not /usr/bin/more but /cygdrive/c/WINDOWS/system32/more.com)

Currently, the keybord inputs are sent only to 'yes' rather than 'more.com'
in the above case.

This does not happen in:
$ yes | cat -n | less
because less is a cygwin program which opens '/dev/tty' rather than 'CONIN$'.

Anyway, I'll fix that.

-- 
Takashi Yano <[email-masked]>

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