From: Tim Starling Date: Tue, 1 Nov 2005 00:57:13 +0000 (+0000) Subject: Fix for some odd problems when reading from a non-tty X-Git-Tag: 1.6.0~1256 X-Git-Url: http://git.cyclocoop.org//%22%22.str_replace%28%27%22%27%2C?a=commitdiff_plain;h=5b83a481db4ad10b3065abfc2573438071b7c718;p=lhc%2Fweb%2Fwiklou.git Fix for some odd problems when reading from a non-tty --- 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; } }