protected function runProcess(Process $process, $mustRun = false, $quiet = true)
{
$this->output->writeln("Running command: <info>" . $process->getCommandLine() . "</info>", OutputInterface::VERBOSITY_VERBOSE);
try {
$process->mustRun($quiet ? null : function ($type, $buffer) {
$this->output->write(preg_replace('/^/m', ' ', $buffer));
});
} catch (ProcessFailedException $e) {
if (!$mustRun) {
return $process->getExitCode();
}
// The default for ProcessFailedException is to print the entire
// STDOUT and STDERR. But if $quiet is disabled, then the user will
// have already seen the command's output. So we need to re-throw
// the exception with a much shorter message.
$message = "The command failed with the exit code: " . $process->getExitCode();
$message .= "\n\nFull command: " . $process->getCommandLine();
if ($quiet) {
$message .= "\n\nError output:\n" . $process->getErrorOutput();
}
throw new \Exception($message);
}
$output = $process->getOutput();
return $output ? rtrim($output) : true;
}