Symfony\Component\Process\Process::setTty PHP Method

setTty() public method

Enables or disables the TTY mode.
public setTty ( boolean $tty ) : self
$tty boolean True to enabled and false to disable
return self The current Process instance
    public function setTty($tty)
    {
        if ('\\' === DIRECTORY_SEPARATOR && $tty) {
            throw new RuntimeException('TTY mode is not supported on Windows platform.');
        }
        if ($tty) {
            static $isTtySupported;
            if (null === $isTtySupported) {
                $isTtySupported = (bool) @proc_open('echo 1 >/dev/null', array(array('file', '/dev/tty', 'r'), array('file', '/dev/tty', 'w'), array('file', '/dev/tty', 'w')), $pipes);
            }
            if (!$isTtySupported) {
                throw new RuntimeException('TTY mode requires /dev/tty to be read/writable.');
            }
        }
        $this->tty = (bool) $tty;
        return $this;
    }

Usage Example

 /**
  * Executes the command $cmd
  *
  * @param string $cmd
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @param bool $silent
  * @param bool $tty
  * @return string|void
  */
 public function exec($cmd, $output = null, $silent = FALSE, $tty = FALSE)
 {
     $process = new Process($cmd);
     if ($tty) {
         $process->setTty(TRUE);
     }
     $process->setTimeout(null);
     if (!$silent && $output) {
         $output->writeln($this->messageService->lightGray('-------------------------------------------------'));
         $output->writeln($this->messageService->lightGray('Executing: ' . $cmd));
         $messageService = $this->messageService;
         $process->setTimeout(3600);
         $process->start();
         $process->wait(function ($type, $buffer) use($output, $messageService) {
             if (Process::ERR === $type) {
                 $output->writeln($messageService->red('----> ERROR START'));
                 $output->write($messageService->red('----> ' . $buffer));
                 $output->writeln($messageService->red('----> ERROR END'));
             } else {
                 $output->write($messageService->green($buffer));
             }
         });
     } else {
         $process->run();
     }
     return $process->getOutput();
 }
All Usage Examples Of Symfony\Component\Process\Process::setTty