/** * Execute interactive * * @param array $opts Option array * @return $this * @throws \Exception */ public function execInteractive(array $opts = null) { $this->checkCommand(); ConsoleUtility::verboseWriteln('EXEC::INTERACTIVE', $this->command->build()); $descriptorSpec = array(0 => array('file', 'php://stdin', 'r'), 1 => array('file', 'php://stdout', 'w'), 2 => array('file', 'php://stderr', 'w')); $process = proc_open($this->command->build(), $descriptorSpec, $pipes); if (is_resource($process)) { if (!empty($opts['startupCallback']) && is_callable($opts['startupCallback'])) { $opts['startupCallback']($process); } do { if (is_resource($process)) { $status = proc_get_status($process); if (!empty($status) && !empty($opts['runningCallback']) && is_callable($opts['runningCallback'])) { $opts['runningCallback']($process, $status); } } else { break; } usleep(100 * 1000); } while (!empty($status) && is_array($status) && $status['running'] === true); if (is_resource($process)) { proc_close($process); } $this->returnCode = $status['exitcode']; $this->runFinishers(); if ($status['signaled'] === true && $status['exitcode'] === -1) { // user may hit CTRL+C ConsoleUtility::getOutput()->writeln('<comment>Processed stopped by signal</comment>'); } elseif ($this->strictMode && $this->returnCode !== 0) { throw $this->generateException('Process ' . $this->command->getCommand() . ' did not finished successfully'); } } else { throw $this->generateException('Process ' . $this->command->getCommand() . ' could not be started'); } return $this; }
/** * Append another command builder * * @param CommandBuilderInterface $command Command builder * @param boolean $inline Add command as inline string (one big parameter) * * @return $this */ public function append(CommandBuilderInterface $command, $inline = true) { // Check if sub command is executeable if (!$command->isExecuteable()) { throw new \RuntimeException('Sub command "' . $command->getCommand() . '" is not executable or available'); } if ($inline) { // Inline, one big parameter $this->addArgument($command->build()); } else { // Append each as own argument $this->addArgument($command->command); $this->argumentList = array_merge($this->argumentList, $command->argumentList); } return $this; }