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
 /**
  * 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();
 }
 /**
  * Adds a virtual host name to the hosts file of the host system.
  *
  * @param VirtualHost[] $vhosts
  */
 public function addServerToHostsFile(array $vhosts)
 {
     // Get the docker-machine VM ip address.
     $dockerMachineIpAddress = Application::getDocker()->getDockerMachineIpAddress('default');
     $vhostServerNames = [];
     foreach ($vhosts as $vhost) {
         $vhostServerNames[] = $vhost->getServerName();
     }
     $vhostServerNames = join(' ', $vhostServerNames);
     $found = false;
     $hosts = file('/etc/hosts');
     if ($hosts) {
         foreach ($hosts as $line) {
             $line = str_replace(array("\t", '#'), ' ', $line);
             preg_match_all('#^(.*?) (.*)$#', $line, $matches);
             if (!empty($matches[1][0]) && !empty($matches[2][0])) {
                 $ip = trim($matches[1][0]);
                 $host = trim($matches[2][0]);
                 if ($ip == $dockerMachineIpAddress && $host == $vhostServerNames) {
                     $found = true;
                     break;
                 }
             }
         }
         if (!$found) {
             $process = new Process(sprintf('sudo sh -c "echo \'%s %s\' >> /etc/hosts"', $dockerMachineIpAddress, $vhostServerNames . ' '));
             $process->setTty(true);
             $process->run();
             print $process->getOutput();
         }
     }
 }
 /**
  * Run the installation helper.
  *
  * @return void
  */
 public function install()
 {
     if (!$this->command->output->confirm('Would you like to install the Boilerplate dependencies?', true)) {
         return;
     }
     $composer = $this->findComposer();
     $this->command->output->writeln('<info>Running Composer...</info>');
     $commands = [$composer . ' install --no-scripts', $composer . ' run-script post-root-package-install', $composer . ' run-script post-install-cmd', $composer . ' run-script post-create-project-cmd'];
     if ($this->command->input->getOption('no-ansi')) {
         $commands = array_map(function ($value) {
             return $value . ' --no-ansi';
         }, $commands);
     }
     $process = new Process(implode(' && ', $commands), $this->command->path, null, null, null);
     if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) {
         $process->setTty(true);
     }
     $process->run(function ($type, $line) {
         $this->command->output->write($line);
     });
     if (!$process->isSuccessful()) {
         throw new ProcessFailedException($process);
     }
     $this->command->dependencies_installed = true;
     $this->command->output->writeln('<info>Dependencies Installed!</info>');
 }
Example #4
0
 /**
  * Execute the command.
  *
  * @param  InputInterface  $input
  * @param  OutputInterface  $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!class_exists('ZipArchive')) {
         throw new RuntimeException('The Zip PHP extension is not installed. Please install it and try again.');
     }
     $this->verifyApplicationDoesntExist($directory = $input->getArgument('name') ? getcwd() . '/' . $input->getArgument('name') : getcwd());
     $output->writeln('<info>Crafting application...</info>');
     $version = $this->getVersion($input);
     $this->download($zipFile = $this->makeFilename(), $version)->extract($zipFile, $directory)->cleanUp($zipFile);
     $composer = $this->findComposer();
     $commands = [$composer . ' install --no-scripts', $composer . ' run-script post-root-package-install', $composer . ' run-script post-install-cmd', $composer . ' run-script post-create-project-cmd'];
     if ($input->getOption('no-ansi')) {
         $commands = array_map(function ($value) {
             return $value . ' --no-ansi';
         }, $commands);
     }
     $process = new Process(implode(' && ', $commands), $directory, null, null, null);
     if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) {
         $process->setTty(true);
     }
     $process->run(function ($type, $line) use($output) {
         $output->write($line);
     });
     $output->writeln('<comment>Application ready! Build something amazing.</comment>');
 }
Example #5
0
 protected function shell($command, $workingDirectory = '.', $asTty = false)
 {
     $process = new Process($command, $workingDirectory, null, null, null);
     $process->setTty($asTty);
     return $process->run(function ($type, $buffer) {
         echo $buffer;
     }) == 0;
 }
 /**
  * Run the installation helper.
  *
  * @return void
  */
 public function install()
 {
     $process = new Process($this->command(), $this->command->path);
     if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) {
         $process->setTty(true);
     }
     $process->run(function ($type, $line) {
         $this->command->output->write($line);
     });
 }
Example #7
0
 /**
  * @param string      $cmd
  * @param string|null $workingDirectory
  * @param bool        $isDryRun
  * @param bool        $tty
  * @return $this
  */
 public function add($cmd, $workingDirectory, $isDryRun = false, $tty = false)
 {
     $process = null;
     if (!$isDryRun) {
         $process = new Process($cmd);
         $process->setTty($tty);
         $process->setWorkingDirectory($workingDirectory);
         $this->parallelProcessRunner->add($process);
     }
     return $this;
 }
Example #8
0
 private function composerUpdate()
 {
     $process = new Process('composer update "flashtag/*"');
     $process->setTty(true);
     $process->run(function ($type, $buffer) {
         if ('err' === $type) {
             echo $buffer;
         } else {
             echo $buffer;
         }
     });
 }
Example #9
0
 /**
  * Run the given script on the given host.
  *
  * @param  string  $host
  * @param  \Laravel\Envoy\Task  $task
  * @return int
  */
 protected function getProcess($host, Task $task)
 {
     $target = $this->getConfiguredServer($host) ?: $host;
     if (in_array($target, ['local', 'localhost', '127.0.0.1'])) {
         $process = new Process($task->script);
         $process->setTty(true);
     } else {
         $delimiter = 'EOF-LARAVEL-ENVOY';
         $process = new Process("ssh {$target} 'bash -se' << \\{$delimiter}" . PHP_EOL . 'set -e' . PHP_EOL . $task->script . PHP_EOL . $delimiter);
     }
     return [$target, $process->setTimeout(null)];
 }
Example #10
0
 /**
  * @param string $theme
  */
 private function install($theme)
 {
     $this->info(sprintf("Installing theme %s", $theme));
     $process = new Process(sprintf('composer require "%s"', $theme));
     $process->setTty(true);
     $process->run(function ($type, $buffer) {
         if ('err' === $type) {
             echo $buffer;
         } else {
             echo $buffer;
         }
     });
 }
Example #11
0
 /**
  * @param string $cmd
  * @param bool   $isDryRun
  * @param bool   $tty
  * @return null|Process
  */
 public function runCommand($cmd, $isDryRun = false, $tty = false)
 {
     $this->getLogger()->debug($cmd, ['dry_run' => $isDryRun, 'tty' => $tty]);
     $process = null;
     if (!$isDryRun) {
         $process = new Process($cmd);
         $process->setTty($tty);
         $process->mustRun();
         $process->setTimeout(null);
         $process->setIdleTimeout(null);
         $process->setWorkingDirectory($this->getRepositoryPath());
     }
     return $process;
 }
Example #12
0
 /**
  * @param $command
  * @param $option
  */
 public function process($command, array $option = null)
 {
     if (true === is_array($command)) {
         $command = implode(' ', $command);
     }
     if (true === isset($option['timeout'])) {
         $timeout = $option['timeout'];
     } else {
         $timeout = null;
     }
     if (true === isset($option['tty'])) {
         $tty = $option['tty'];
     } else {
         $tty = false;
     }
     if ($this->verbose) {
         $print = true;
         $this->message('IN >> ' . $command);
     } else {
         if (true === isset($option['print'])) {
             $print = $option['print'];
         } else {
             $print = true;
             $this->message($command);
         }
     }
     $process = new Process($command);
     $process->setTty($tty);
     $process->setTimeout($timeout);
     $process->run(function ($type, $buf) use($print) {
         if (true == $print) {
             $buffers = explode(PHP_EOL, trim($buf, PHP_EOL));
             foreach ($buffers as $buffer) {
                 if (Process::ERR === $type) {
                     echo 'ERR > ' . $buffer . PHP_EOL;
                 } else {
                     if ('reach it successfully.' == $buffer) {
                         print_r($command);
                     }
                     echo \Peanut\Console\Color::text('OUT > ', 'black') . $buffer . PHP_EOL;
                 }
             }
         }
     });
     if (!$process->isSuccessful() && $process->getErrorOutput()) {
         throw new \Peanut\Console\Exception(trim($process->getErrorOutput()));
     }
     return new \Peanut\Console\Result($process->getErrorOutput() . $process->getOutput());
 }
Example #13
0
 /**
  * Execute the command.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $this->verifyApplicationDoesntExist($directory = $input->getArgument('name') ? getcwd() . '/' . $input->getArgument('name') : getcwd(), $output);
     $output->writeln('<info>Crafting Lucid application...</info>');
     /*
      * @TODO: Get Lucid based on the Laravel version.
      */
     $process = new Process($this->findComposer() . ' create-project laravel/laravel ' . $directory);
     if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) {
         $process->setTty(true);
     }
     $process->run(function ($type, $line) use($output) {
         $output->write($line);
     });
     $output->writeln('<comment>Application ready! Make your dream a reality.</comment>');
 }
Example #14
0
 /**
  * Execute the command.
  *
  * @param  InputInterface  $input
  * @param  OutputInterface  $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!class_exists('ZipArchive')) {
         throw new RuntimeException('The Zip PHP extension is not installed. Please install it and try again.');
     }
     $this->verifyApplicationDoesntExist($directory = getcwd() . '/' . $input->getArgument('name'), $output);
     $output->writeln('<info>Crafting application...</info>');
     $version = $this->getVersion($input);
     $this->download($zipFile = $this->makeFilename(), $version)->extract($zipFile, $directory)->cleanUp($zipFile);
     $composer = $this->findComposer();
     $commands = [$composer . ' install --no-scripts'];
     $process = new Process(implode(' && ', $commands), $directory, null, null, null);
     $process->setTty(true);
     $process->run(function ($type, $line) use($output) {
         $output->write($line);
     });
     $output->writeln('<comment>Application ready! Build something amazing.</comment>');
 }
Example #15
0
 public function executeCommand($command, $stdIn = null, $quiet = false)
 {
     $this->tty = $stdIn instanceof TTY;
     $command = $this->decorator->decorateCommand($command, $this);
     $this->process = $process = new Process($command, array_shift($this->workingDirectoriesStack));
     $process->setTimeout(null);
     if (null !== $stdIn) {
         if ($this->tty) {
             $process->setTty(true);
         } else {
             $process->setStdin($stdIn);
         }
     }
     $output = $this->getOutput();
     if ($output && $output->getVerbosity() >= $output::VERBOSITY_VERBOSE) {
         $output->writeln(sprintf('$ %s', $command));
         $start = true;
         $prefix = ' ---> ';
         $process->start(function ($type, $buffer) use($output, &$start, $prefix, $quiet) {
             if ($start) {
                 $buffer = $prefix . $buffer;
                 $start = false;
             }
             if ($buffer[strlen($buffer) - 1] == "\n") {
                 $start = true;
                 $buffer = strtr(substr($buffer, 0, -1), ["\n" => "\n" . $prefix]) . "\n";
             } else {
                 $buffer = strtr($buffer, ["\n" => "\n" . $prefix]);
             }
             $quiet || $output->write($buffer);
         });
         $process->wait();
     } else {
         $process->run();
     }
     if ($process->getExitCode() != 0) {
         throw new ProcessFailedException($process);
     }
     return $process->getOutput();
 }
 /**
  * @param bool $dryRun
  * @param bool $gitReAdd
  */
 public function fix($dryRun = false, $gitReAdd = false)
 {
     $this->output->writeln('<info>Fixing PHP code style compliance</info>');
     if ($dryRun) {
         $this->output->writeln("<info>Dry run mode, no changes will be made</info>");
     }
     foreach ($this->files as $file) {
         $this->output->writeln('<info>' . ($dryRun ? 'Analysing' : 'Fixing') . ' file ' . $file . '</info>');
         $command = $dryRun ? "php bin/phpcs --standard={$this->ruleset} --report-full --report-diff {$file}" : "php bin/phpcbf --standard={$this->ruleset} --extensions=php,inc {$file}";
         if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) {
             $this->output->writeln("<info>Running: {$command}</info>");
         }
         $process = new Process($command);
         if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG || $dryRun) {
             $process->setTty(true);
         }
         $process->run();
         if ($gitReAdd) {
             (new Process("git add {$file}"))->run();
         }
     }
 }
Example #17
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     if (!class_exists('ZipArchive')) {
         throw new RuntimeException('Yo, the Zip PHP extension is not installed. Please install it and try again bruv.');
     }
     $this->assertApplicationDoesNotExist($directory = $input->getArgument('name') ? getcwd() . '/' . $input->getArgument('name') : getcwd());
     $output->writeln('<info>Hold on families..</info>');
     $version = $this->getVersion($input);
     $this->download($zipFile = $this->makeFileName(), $version)->extract($zipFile, $directory)->cleanUp($zipFile);
     if ($input->getOption('phpstorm')) {
         $this->addHelperFile($directory);
     }
     $composer = $this->findComposer();
     $commands = [$composer . ' install --no-scripts', $composer . ' run-script post-root-package-install', $composer . ' run-script post-install-cmd', $composer . ' run-script post-create-project-cmd'];
     $process = new Process(implode(' && ', $commands), $directory, null, null, null);
     if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) {
         $process->setTty(true);
     }
     $process->run(function ($type, $line) use($output) {
         $output->write($line);
     });
     $output->writeln('<comment>Laravel ready!</comment>');
 }
 protected function runCommands($commands, $output, $quiet = false)
 {
     $commands = (array) $commands;
     $process = new Process(implode(' && ', $commands), $this->directory, null, null, null);
     if ($quiet === false && '\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) {
         $process->setTty(true);
     }
     $process->run(function ($type, $line) use($output, $quiet) {
         if ($quiet === false) {
             $output->write($line);
         }
     });
 }
 /**
  * Prepares a process to run and returns it (no execution).
  *
  * @param $command
  *      The command with parameters.
  * @param $serverSuffix
  *      (Optional) The server suffix for identification.
  * @param string $path
  *      (Optional) The path.
  *
  * @return \Symfony\Component\Process\Process
  *      The prepared process to execute.
  */
 private function prepareProcess($command, $serverSuffix = null, $path = null)
 {
     $environmentVariables = $this->environmentVariables;
     if ($serverSuffix) {
         $environmentVariables += ['SERVER_SUFFIX' => $serverSuffix];
     }
     if ($this->project) {
         $environmentVariables += ['PROJECT' => $this->project->getShortName(), 'VHOST_NAME' => $this->project->getVhostName(), 'GIT_BRANCH' => $this->gitBranch];
     }
     $process = new Process($command, $path === null ? self::DOCKER_COMPOSE_FILE_PATH : $path, $environmentVariables);
     $process->setTty(true);
     $process->setTimeout(null);
     $process->setIdleTimeout(null);
     return $process;
 }
Example #20
0
 function it_should_run_process_builder(ProcessBuilder $builder, Process $process)
 {
     $process->run(Argument::any())->shouldBeCalled();
     $process->setTty(false)->shouldBeCalled();
     $this->run($builder)->shouldHaveType('Symfony\\Component\\Process\\Process');
 }