/** * @param string $command * @param OutputInterface $output * @param array $options Process options, includes: * bool logfile * bool stderr * bool stdout * int timeout * string input * array env * string cwd * @return Process */ public static function process(OutputInterface $output, $command, array $options = []) { $options = array_merge(['stderr' => true, 'stdout' => $output->isDebug(), 'timeout' => 60, 'input' => null, 'env' => null, 'cwd' => null, 'logfile' => null], $options); $output->writeDebug(str_repeat('-', 55)); $output->writeDebug("Executing command: {$command}"); $output->writeDebug(str_repeat('-', 55)); $process = new Process($command, $options['cwd'], $options['env'], $options['input'], $options['timeout']); $process->run(function ($type, $buffer) use($output, $options) { if ($type === Process::ERR) { if ($options['stderr']) { $output->writeStderr($buffer); } return; } if (!$options['stdout']) { return; } $buffer = trim($buffer, "\n"); if (empty($buffer)) { return; } $output->writeStdout($buffer); }); $output->writeDebug(str_repeat('-', 55)); return $process; }