public function run($commandline, $options = array())
{
if (!$this->node) {
throw new \RuntimeException("Node is not defined to run the command.");
}
if (is_array($commandline)) {
$commandline = implode(" && ", $commandline);
}
$this->runtimeTask->getOutput()->writeln($this->getRemoteInfoPrefix() . "<info>Run: </info>{$commandline}");
$realCommand = $this->compileRealCommand($commandline, $options);
if ($this->runtimeTask->getOutput()->isVeryVerbose()) {
$this->runtimeTask->getOutput()->writeln($this->getRemoteInfoPrefix() . "<info>Real command: </info>{$realCommand}");
}
$ssh = $this->getSSH();
$self = $this;
if (isset($options["timeout"])) {
$ssh->setTimeout($options["timeout"]);
} else {
$ssh->setTimeout(null);
}
$resultContent = null;
$ssh->exec($realCommand, function ($buffer) use($self, &$resultContent) {
$self->getRuntimeTask()->getOutput()->write($buffer);
$resultContent .= $buffer;
});
$returnCode = $ssh->getExitStatus();
return new ProcessResult($returnCode, $resultContent);
}