spectre.console icon indicating copy to clipboard operation
spectre.console copied to clipboard

Detect non-interactive console via Console.IsInputRedirected instead of Environment.UserInteractive

Open bastianeicher opened this issue 3 years ago • 6 comments

Environment.UserInteractive is false for SSH sessions on Windows, even though they are interactive. Detecting non-interactive sessions via redirected stdin instead seems more robust.

bastianeicher avatar May 04 '22 21:05 bastianeicher

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 04 '22 21:05 CLAassistant

@bastianeicher Could you rebase this PR against the main branch?

patriksvensson avatar Jun 30 '22 18:06 patriksvensson

Sure thing. :) Rebased.

bastianeicher avatar Jul 01 '22 07:07 bastianeicher

@bastianeicher The code in this PR does not compile.

The type or namespace name 'IsInputRedirected' does not exist in the namespace 'Spectre.Console'

patriksvensson avatar Jul 01 '22 08:07 patriksvensson

I was thinking, perhaps it would be better adding an SSH enriched, and checking whether or not SSH_CLIENT, SSH_CONNECTION or SSH_TTY environment variables are defined.

patriksvensson avatar Jul 01 '22 08:07 patriksvensson

@bastianeicher The code in this PR does not compile.

Sorry about that. It did compile before the rebase but I didn't check it after. Fixed by replacing Console with System.Console.

I was thinking, perhaps it would be better adding an SSH enriched, and checking whether or not SSH_CLIENT, SSH_CONNECTION or SSH_TTY environment variables are defined.

SSH on Windows is not the only case where Environment.UserInteractive doesn't return a reliable value. For example, on non-Windows platforms the value is simply hardcoded to true. So I still think checking System.Console.IsInputRedirected here is a better option.

bastianeicher avatar Jul 01 '22 08:07 bastianeicher