function ProcessHelper::run
Runs an external process.
Parameters
array|Process $cmd An instance of Process or an array of the command and arguments:
callable|null $callback A PHP callback to run whenever there is some: output available on STDOUT or STDERR
1 call to ProcessHelper::run()
- ProcessHelper::mustRun in vendor/
symfony/ console/ Helper/ ProcessHelper.php - Runs the process.
File
-
vendor/
symfony/ console/ Helper/ ProcessHelper.php, line 35
Class
- ProcessHelper
- The ProcessHelper class provides helpers to run external processes.
Namespace
Symfony\Component\Console\HelperCode
public function run(OutputInterface $output, array|Process $cmd, ?string $error = null, ?callable $callback = null, int $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE) : Process {
if (!class_exists(Process::class)) {
throw new \LogicException('The ProcessHelper cannot be run as the Process component is not installed. Try running "compose require symfony/process".');
}
if ($output instanceof ConsoleOutputInterface) {
$output = $output->getErrorOutput();
}
$formatter = $this->getHelperSet()
->get('debug_formatter');
if ($cmd instanceof Process) {
$cmd = [
$cmd,
];
}
if (\is_string($cmd[0] ?? null)) {
$process = new Process($cmd);
$cmd = [];
}
elseif (($cmd[0] ?? null) instanceof Process) {
$process = $cmd[0];
unset($cmd[0]);
}
else {
throw new \InvalidArgumentException(\sprintf('Invalid command provided to "%s()": the command should be an array whose first element is either the path to the binary to run or a "Process" object.', __METHOD__));
}
if ($verbosity <= $output->getVerbosity()) {
$output->write($formatter->start(spl_object_hash($process), $this->escapeString($process->getCommandLine())));
}
if ($output->isDebug()) {
$callback = $this->wrapCallback($output, $process, $callback);
}
$process->run($callback, $cmd);
if ($verbosity <= $output->getVerbosity()) {
$message = $process->isSuccessful() ? 'Command ran successfully' : \sprintf('%s Command did not run successfully', $process->getExitCode());
$output->write($formatter->stop(spl_object_hash($process), $message, $process->isSuccessful()));
}
if (!$process->isSuccessful() && null !== $error) {
$output->writeln(\sprintf('<error>%s</error>', $this->escapeString($error)));
}
return $process;
}