From d1e81109ba1b0cb566c33aa4c8eaa7e156a4d5c5 Mon Sep 17 00:00:00 2001 From: Developer Date: Thu, 19 Mar 2026 20:32:31 -0400 Subject: [PATCH] fix: Handle read gracefully when stdin is piped (check terminal with -t 0) --- launcher.sh | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/launcher.sh b/launcher.sh index 0b08c10..bb06025 100755 --- a/launcher.sh +++ b/launcher.sh @@ -80,6 +80,24 @@ run_module() { read -p "Press Enter to continue..." < /dev/tty } +############################################################################# +# TERMINAL INPUT HELPER +############################################################################# + +# Safe read that handles both interactive and piped scenarios +safe_read() { + local prompt="$1" + local varname="$2" + + if [ -t 0 ]; then + # Terminal available, normal read + read -p "$prompt" "$varname" + else + # No terminal (piped stdin), accept input or skip + read -p "$prompt" "$varname" 2>/dev/null || eval "$varname=''" + fi +} + ############################################################################# # SYSTEM INFO DISPLAY (Quick View) ############################################################################# @@ -674,7 +692,13 @@ startup_detection() { print_success "Detection complete! Cached for 1 hour." echo "" - read -p "Press Enter to continue..." < /dev/tty + # Try to read from tty if available, otherwise from stdin + if [ -t 0 ]; then + read -p "Press Enter to continue..." + else + # stdin available (e.g., from pipe), use it + read -p "Press Enter to continue..." || true + fi fi } @@ -688,7 +712,17 @@ main() { while true; do show_main_menu - read -r choice < /dev/tty + + # Handle read with/without terminal + if [ -t 0 ]; then + read -r choice + else + read -r choice || { + echo "" + echo "stdin closed, exiting launcher" + exit 0 + } + fi case $choice in 1) run_module "diagnostics" "system-health-check.sh" ;;