pharext\ExecCmd::run PHP Method

run() public method

Run the command
public run ( array $args = null ) : ExecCmd
$args array
return ExecCmd self
    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;
    }

Usage Example

Example #1
0
 /**
  * @param bool $verbose
  * @return \pharext\Tempdir
  */
 public function run($verbose = false)
 {
     if ($verbose !== false) {
         printf("Fetching %s ...\n", $this->source);
     }
     $local = new Tempdir("gitclone");
     $cmd = new ExecCmd("git", $verbose);
     if (strlen($this->branch)) {
         $cmd->run(["clone", "--depth", 1, "--branch", $this->branch, $this->source, $local]);
     } else {
         $cmd->run(["clone", $this->source, $local]);
     }
     return $local;
 }
All Usage Examples Of pharext\ExecCmd::run