From dfc4072181aa8bd588742034177a618b7f12dbdb Mon Sep 17 00:00:00 2001 From: Will Shuttleworth Date: Mon, 2 Jun 2025 08:41:25 +0000 Subject: [PATCH] stty: fix output redirection (#8016) * stty: fix output redirection * Revert "stty: fix output redirection" This reverts commit 604de7c4de6f51a6bcd495ccda11602c12804493. * stty: fix output redirection by trying /dev/tty before stdout --- src/uu/stty/src/stty.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index 5cc24a596..4e2ceaa3f 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -142,7 +142,18 @@ impl<'a> Options<'a> { .custom_flags(O_NONBLOCK) .open(f)?, ), - None => Device::Stdout(stdout()), + // default to /dev/tty, if that does not exist then default to stdout + None => { + if let Ok(f) = std::fs::OpenOptions::new() + .read(true) + .custom_flags(O_NONBLOCK) + .open("/dev/tty") + { + Device::File(f) + } else { + Device::Stdout(stdout()) + } + } }, settings: matches .get_many::(options::SETTINGS)