public function run($command, $args = array())
{
$process = $this->getProcess($command, $args);
if ($this->logger) {
$this->logger->info(sprintf('run command: %s "%s" ', $command, implode(' ', $args)));
$before = microtime(true);
}
$process->run();
$output = $process->getOutput();
if ($this->logger && $this->debug) {
$duration = microtime(true) - $before;
$this->logger->debug(sprintf('last command (%s) duration: %sms', $command, sprintf('%.2f', $duration * 1000)));
$this->logger->debug(sprintf('last command (%s) return code: %s', $command, $process->getExitCode()));
$this->logger->debug(sprintf('last command (%s) output: %s', $command, $output));
}
if (!$process->isSuccessful()) {
$error = sprintf("error while running %s\n output: \"%s\"", $command, $process->getErrorOutput());
if ($this->logger) {
$this->logger->error($error);
}
if ($this->debug) {
throw new ProcessException($process);
}
return;
}
return $output;
}