diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index acd32687880c..410900cc2bcf 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -36,6 +36,7 @@ use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Input\StreamableInputInterface; use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -946,6 +947,16 @@ protected function configureIO(InputInterface $input, OutputInterface $output) if (true === $input->hasParameterOption(['--no-interaction', '-n'], true)) { $input->setInteractive(false); + } elseif (\function_exists('posix_isatty')) { + $inputStream = null; + + if ($input instanceof StreamableInputInterface) { + $inputStream = $input->getStream(); + } + + if (!@posix_isatty($inputStream) && false === getenv('SHELL_INTERACTIVE')) { + $input->setInteractive(false); + } } switch ($shellVerbosity = (int) getenv('SHELL_VERBOSITY')) { diff --git a/src/Symfony/Component/Console/Tester/ApplicationTester.php b/src/Symfony/Component/Console/Tester/ApplicationTester.php index 4f99da18d5f8..ced56cff208b 100644 --- a/src/Symfony/Component/Console/Tester/ApplicationTester.php +++ b/src/Symfony/Component/Console/Tester/ApplicationTester.php @@ -59,12 +59,19 @@ public function run(array $input, $options = []) $this->input->setInteractive($options['interactive']); } + $shellInteractive = getenv('SHELL_INTERACTIVE'); + if ($this->inputs) { $this->input->setStream(self::createStream($this->inputs)); + putenv('SHELL_INTERACTIVE=1'); } $this->initOutput($options); - return $this->statusCode = $this->application->run($this->input, $this->output); + $this->statusCode = $this->application->run($this->input, $this->output); + + putenv($shellInteractive ? "SHELL_INTERACTIVE=$shellInteractive" : 'SHELL_INTERACTIVE'); + + return $this->statusCode; } } diff --git a/src/Symfony/Component/Console/Tests/phpt/uses_stdin_as_interactive_input.phpt b/src/Symfony/Component/Console/Tests/phpt/uses_stdin_as_interactive_input.phpt deleted file mode 100644 index db1bb4ce436e..000000000000 --- a/src/Symfony/Component/Console/Tests/phpt/uses_stdin_as_interactive_input.phpt +++ /dev/null @@ -1,28 +0,0 @@ ---STDIN-- -Hello World ---FILE-- -register('app') - ->setCode(function(InputInterface $input, OutputInterface $output) { - $output->writeln((new QuestionHelper())->ask($input, $output, new Question('Foo?'))); - }) - ->getApplication() - ->setDefaultCommand('app', true) - ->run() -; ---EXPECT-- -Foo?Hello World