public function run(array $args = null)
{
$exec = escapeshellcmd($this->command);
if ($args) {
$exec .= " " . implode(" ", array_map("escapeshellarg", (array) $args));
}
if ($this->sudo) {
$this->suExec(sprintf($this->sudo . " 2>&1", $exec), $this->verbose);
} elseif ($this->verbose) {
ob_start(function ($s) {
$this->output .= $s;
return $s;
}, 1);
passthru($exec, $this->status);
ob_end_flush();
} elseif ($this->verbose !== false) {
ob_start([$this, "progress"], 1);
passthru($exec . " 2>&1", $this->status);
ob_end_flush();
} else {
exec($exec . " 2>&1", $output, $this->status);
$this->output = implode("\n", $output);
}
if ($this->status) {
throw new Exception("Command {$exec} failed ({$this->status})");
}
return $this;
}