Skip to content

Conversation

@philwalk
Copy link
Contributor

@philwalk philwalk commented Jan 23, 2025

Test whether running in a terminal, and only call stty if appropriate.

This avoids seeing stty error messages when piping text to a scala script STDIN.

Closes #22443

# clear on error so we don't later try to restore them
if [[ ! $? ]]; then
saved_stty=""
if [ -e /usr/bin/tty -a "`tty`" != "not a tty" -a ! -p /dev/stdin ]; then
Copy link
Member

@hamzaremmal hamzaremmal Mar 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked and played a bit with the locale and it seems that tty will always output 'not a tty' regardless of the current locale. Which means that we can rely on that output being in the same language.

% date Sun Mar 9 14:58:45 CET 2025 % tty < /dev/null not a tty % export LANG=fr_FR.UTF-8 % date Dim 9 mar 2025 14:59:00 CET % tty < /dev/null not a tty
saved_stty=$(stty -g 2>/dev/null)
# clear on error so we don't later try to restore them
if [[ ! $? ]]; then
saved_stty=""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you clear the cached stty but you don't clear the isterminal variable. The code below will try to recover the stty if isterminal is set to 1. Locally, recovering the stty with these parameters might be problematic:

% stty speed 9600 baud; lflags: echoe echoke echoctl pendin iflags: iutf8 oflags: -oxtabs cflags: cs8 -parenb % stty "" stty: illegal option -- usage: stty [-a | -e | -g] [-f file] [arguments]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. Clearing isterminal when stty is cleared seems correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants