diff --git a/src/CliPrompt.php b/src/CliPrompt.php index b781a8d..9fdef58 100644 --- a/src/CliPrompt.php +++ b/src/CliPrompt.php @@ -59,17 +59,19 @@ public static function hiddenPrompt($allowFallback = false) $exe = $tmpExe; } - $answer = self::trimAnswer(shell_exec($exe)); + $output = shell_exec($exe); // clean up if (isset($tmpExe)) { unlink($tmpExe); } - // output a newline to be on par with the regular prompt() - echo PHP_EOL; + if ($output !== null) { + // output a newline to be on par with the regular prompt() + echo PHP_EOL; - return $answer; + return self::trimAnswer($output); + } } if (file_exists('/usr/bin/env')) { @@ -85,12 +87,14 @@ public static function hiddenPrompt($allowFallback = false) if (isset($shell)) { $readCmd = ($shell === 'csh') ? 'set mypassword = $<' : 'read -r mypassword'; $command = sprintf("/usr/bin/env %s -c 'stty -echo; %s; stty echo; echo \$mypassword'", $shell, $readCmd); - $value = self::trimAnswer(shell_exec($command)); + $output = shell_exec($command); - // output a newline to be on par with the regular prompt() - echo PHP_EOL; + if ($output !== null) { + // output a newline to be on par with the regular prompt() + echo PHP_EOL; - return $value; + return self::trimAnswer($output); + } } }