Elgg\CommitMessageGitHookTest::runCmd PHP Method

runCmd() protected method

Executes a command and returns true if the cmd exited with 0.
protected runCmd ( string $cmd, string &$output, array $env = [] ) : boolean
$cmd string Shell command to execute
$output string Output from stdout and stderr will be written to this variable
$env array Array of environment variables to be passed to sub-process
return boolean Result depending on process exit code.
    protected function runCmd($cmd, &$output, array $env = array())
    {
        $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
        $defaultEnv = array('PATH' => getenv('PATH'));
        $env = array_merge($defaultEnv, $env);
        $process = proc_open($cmd, $descriptorspec, $pipes, null, $env);
        $this->assertTrue(is_resource($process));
        // unfortunately we separate errors from output, but it should be good enough for current usage
        $output = stream_get_contents($pipes[1]) . stream_get_contents($pipes[2]);
        $exit = proc_close($process);
        return $exit > 0 ? false : true;
    }