Skip to content

Commit

Permalink
Handle shell_exec failures gracefully, closes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek authored Mar 18, 2017
1 parent 8cbe109 commit a19a737
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/CliPrompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand All @@ -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);
}
}
}

Expand Down

0 comments on commit a19a737

Please sign in to comment.