public function execute($binPath = null, $args = null, $env = null)
{
if ($binPath !== null) {
$this->binPath = $binPath;
}
if ($env !== null) {
$this->env = $env;
}
if ($args !== null) {
$this->args = $args;
}
$this->cmd = $this->binPath . static::buildArgs($this->args) . ($this->outputErrors ? ' 2>&1' : '');
if (isset($this->setUser) || isset($this->setGroup)) {
if (isset($this->setUser) && isset($this->setGroup) && $this->setUser !== $this->setGroup) {
$this->cmd = 'sudo -g ' . escapeshellarg($this->setGroup) . ' -u ' . escapeshellarg($this->setUser) . ' ' . $this->cmd;
} else {
$this->cmd = 'su ' . escapeshellarg($this->setGroup) . ' -c ' . escapeshellarg($this->cmd);
}
}
if ($this->chroot !== '/') {
$this->cmd = 'chroot ' . escapeshellarg($this->chroot) . ' ' . $this->cmd;
}
if ($this->nice !== null) {
$this->cmd = 'nice -n ' . (int) $this->nice . ' ' . $this->cmd;
}
$pipesDescr = [0 => ['pipe', 'r'], 1 => ['pipe', 'w']];
if ($this->errlogfile !== null && !$this->outputErrors) {
$pipesDescr[2] = ['file', $this->errlogfile, 'a'];
// @TODO: refactoring
}
$this->pd = proc_open($this->cmd, $pipesDescr, $this->pipes, $this->cwd, $this->env);
if ($this->pd) {
$this->setFd($this->pipes[1]);
}
return $this;
}