From 5b83a481db4ad10b3065abfc2573438071b7c718 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Tue, 1 Nov 2005 00:57:13 +0000 Subject: [PATCH] Fix for some odd problems when reading from a non-tty --- install-utils.inc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/install-utils.inc b/install-utils.inc index 6de9377428..5764c52a73 100644 --- a/install-utils.inc +++ b/install-utils.inc @@ -57,10 +57,16 @@ function copydirectory( $source, $dest ) { } function readconsole( $prompt = '' ) { - if ( function_exists( 'posix_isatty' ) && posix_isatty( STDIN ) ) { - $isatty = true; - } else { - $isatty = false; + static $isatty = null, $fp = null; + if ( is_null( $fp ) ) { + $fp = fopen( 'php://stdin', 'r' ); + } + if ( is_null( $isatty ) ) { + if ( !function_exists( 'posix_isatty' ) || posix_isatty( $fp ) ) { + $isatty = true; + } else { + $isatty = false; + } } if ( $isatty && function_exists( 'readline' ) ) { @@ -69,11 +75,12 @@ function readconsole( $prompt = '' ) { if ( $isatty ) { print $prompt; } - $fp = fopen( 'php://stdin', 'r' ); + if ( feof( $fp ) ) { + return false; + } $st = fgets($fp, 1024); if ($st === false) return false; $resp = trim( $st ); - fclose( $fp ); return $resp; } } -- 2.20.1