fix: Handle read gracefully when stdin is piped (check terminal with -t 0)

This commit is contained in:
Developer
2026-03-19 20:32:31 -04:00
parent aabc3cb238
commit d1e81109ba
+36 -2
View File
@@ -80,6 +80,24 @@ run_module() {
read -p "Press Enter to continue..." < /dev/tty 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) # SYSTEM INFO DISPLAY (Quick View)
############################################################################# #############################################################################
@@ -674,7 +692,13 @@ startup_detection() {
print_success "Detection complete! Cached for 1 hour." print_success "Detection complete! Cached for 1 hour."
echo "" 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 fi
} }
@@ -688,7 +712,17 @@ main() {
while true; do while true; do
show_main_menu 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 case $choice in
1) run_module "diagnostics" "system-health-check.sh" ;; 1) run_module "diagnostics" "system-health-check.sh" ;;