From fc8d92e7a2a68a2322e70e91ab830b1f26be1a8c Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 24 Jun 2012 15:55:23 +0200 Subject: [PATCH] Make sure no error is output if env is missing --- src/Composer/IO/ConsoleIO.php | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Composer/IO/ConsoleIO.php b/src/Composer/IO/ConsoleIO.php index b6adc02db..530bea8c3 100644 --- a/src/Composer/IO/ConsoleIO.php +++ b/src/Composer/IO/ConsoleIO.php @@ -162,22 +162,24 @@ class ConsoleIO implements IOInterface return $value; } - // handle other OSs with bash/zsh/ksh/csh if available to hide the answer - $test = "/usr/bin/env %s -c 'echo OK' 2> /dev/null"; - foreach (array('bash', 'zsh', 'ksh', 'csh') as $sh) { - if ('OK' === rtrim(shell_exec(sprintf($test, $sh)))) { - $shell = $sh; - break; + if (file_exists('/usr/bin/env')) { + // handle other OSs with bash/zsh/ksh/csh if available to hide the answer + $test = "/usr/bin/env %s -c 'echo OK' 2> /dev/null"; + foreach (array('bash', 'zsh', 'ksh', 'csh') as $sh) { + if ('OK' === rtrim(shell_exec(sprintf($test, $sh)))) { + $shell = $sh; + break; + } } - } - if (isset($shell)) { - $this->write($question, false); - $readCmd = ($shell === 'csh') ? 'set mypassword = $<' : 'read mypassword'; - $command = sprintf("/usr/bin/env %s -c 'stty -echo; %s; stty echo; echo \$mypassword'", $shell, $readCmd); - $value = rtrim(shell_exec($command)); - $this->write(''); + if (isset($shell)) { + $this->write($question, false); + $readCmd = ($shell === 'csh') ? 'set mypassword = $<' : 'read mypassword'; + $command = sprintf("/usr/bin/env %s -c 'stty -echo; %s; stty echo; echo \$mypassword'", $shell, $readCmd); + $value = rtrim(shell_exec($command)); + $this->write(''); - return $value; + return $value; + } } // not able to hide the answer, proceed with normal question handling