function ProcessExecutor::runProcess
Parameters
string|non-empty-list<string> $command:
array<string, string>|null $env:
mixed $output:
1 call to ProcessExecutor::runProcess()
- ProcessExecutor::doExecute in vendor/
composer/ composer/ src/ Composer/ Util/ ProcessExecutor.php
File
-
vendor/
composer/ composer/ src/ Composer/ Util/ ProcessExecutor.php, line 122
Class
- ProcessExecutor
- @author Robert Schönthal <seroscho@googlemail.com> @author Jordi Boggiano <j.boggiano@seld.be>
Namespace
Composer\UtilCode
private function runProcess($command, ?string $cwd, ?array $env, bool $tty, &$output = null) : ?int {
// On Windows, we don't rely on the OS to find the executable if possible to avoid lookups
// in the current directory which could be untrusted. Instead we use the ExecutableFinder.
if (is_string($command)) {
if (Platform::isWindows() && Preg::isMatch('{^([^:/\\\\]++) }', $command, $match)) {
$command = substr_replace($command, self::escape(self::getExecutable($match[1])), 0, strlen($match[1]));
}
$process = Process::fromShellCommandline($command, $cwd, $env, null, static::getTimeout());
}
else {
if (Platform::isWindows() && \strlen($command[0]) === strcspn($command[0], ':/\\')) {
$command[0] = self::getExecutable($command[0]);
}
$process = new Process($command, $cwd, $env, null, static::getTimeout());
}
if (!Platform::isWindows() && $tty) {
try {
$process->setTty(true);
} catch (RuntimeException $e) {
// ignore TTY enabling errors
}
}
$callback = is_callable($output) ? $output : function (string $type, string $buffer) : void {
$this->outputHandler($type, $buffer);
};
$signalHandler = SignalHandler::create([
SignalHandler::SIGINT,
SignalHandler::SIGTERM,
SignalHandler::SIGHUP,
], function (string $signal) {
if ($this->io !== null) {
$this->io
->writeError('Received ' . $signal . ', aborting when child process is done', true, IOInterface::DEBUG);
}
});
try {
$process->run($callback);
if ($this->captureOutput && !is_callable($output)) {
$output = $process->getOutput();
}
$this->errorOutput = $process->getErrorOutput();
} catch (ProcessSignaledException $e) {
if ($signalHandler->isTriggered()) {
// exiting as we were signaled and the child process exited too due to the signal
$signalHandler->exitWithLastSignal();
}
} finally {
$signalHandler->unregister();
}
return $process->getExitCode();
}