public function execute()
{
$command = $this->getExecCommand();
if (!$command) {
return false;
}
if ($this->useExec) {
$execCommand = $this->captureStdErr ? "{$command} 2>&1" : $command;
exec($execCommand, $output, $this->_exitCode);
$this->_stdOut = implode("\n", $output);
if ($this->_exitCode !== 0) {
$this->_stdErr = $this->_stdOut;
$this->_error = empty($this->_stdErr) ? 'Command failed' : $this->_stdErr;
return false;
}
} else {
$descriptors = array(1 => array('pipe', 'w'), 2 => array('pipe', $this->getIsWindows() ? 'a' : 'w'));
$process = proc_open($command, $descriptors, $pipes, $this->procCwd, $this->procEnv, $this->procOptions);
if (is_resource($process)) {
$this->_stdOut = stream_get_contents($pipes[1]);
$this->_stdErr = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
$this->_exitCode = proc_close($process);
if ($this->_exitCode !== 0) {
$this->_error = $this->_stdErr ? $this->_stdErr : "Failed without error message: {$command}";
return false;
}
} else {
$this->_error = "Could not run command {$command}";
return false;
}
}
$this->_executed = true;
return true;
}