diff --git a/Helper/QuestionHelper.php b/Helper/QuestionHelper.php index 2e5e29eb8..97ccf6861 100644 --- a/Helper/QuestionHelper.php +++ b/Helper/QuestionHelper.php @@ -106,7 +106,7 @@ private function doAsk(OutputInterface $output, Question $question) { $this->writePrompt($output, $question); - $inputStream = $this->inputStream ?: STDIN; + $inputStream = $this->inputStream ?: fopen('php://stdin', 'r'); $autocomplete = $question->getAutocompleterCallback(); if (null === $autocomplete || !self::$stty || !Terminal::hasSttyAvailable()) { @@ -473,7 +473,7 @@ private function validateAttempts(callable $interviewer, OutputInterface $output } catch (\Exception $error) { } - $attempts = $attempts ?? -(int) $this->isTty(); + $attempts = $attempts ?? -(int) $this->askForever(); } throw $error; @@ -506,18 +506,20 @@ private function getShell() return self::$shell; } - private function isTty(): bool + private function askForever(): bool { - if (!\defined('STDIN')) { + $inputStream = $this->inputStream ?: fopen('php://stdin', 'r'); + + if ('php://stdin' !== (stream_get_meta_data($inputStream)['url'] ?? null)) { return true; } if (\function_exists('stream_isatty')) { - return stream_isatty(fopen('php://input', 'r')); + return stream_isatty($inputStream); } if (\function_exists('posix_isatty')) { - return posix_isatty(fopen('php://input', 'r')); + return posix_isatty($inputStream); } return true;