Ejemplo n.º 1
0
 /**
  * @param ConnectionInterface $connection
  * @param CommandInterface    $command
  *
  * @return ResultInterface
  */
 public function exec(ConnectionInterface $connection, CommandInterface $command)
 {
     $command->execBegin();
     fwrite($connection->getConnection(), $command->asString() . PHP_EOL);
     usleep(500000);
     $connection->history()->add($command);
     $commandLineLabel = null;
     if ($connection instanceof TerminalInterface) {
         $commandLineLabel = $connection->getCommandLineLabel();
     }
     $content = self::read($connection->getConnection(), 8192, $commandLineLabel);
     $result = $this->createResult($content, 0, $command);
     $command->execEnd();
     return $result;
 }
Ejemplo n.º 2
0
Archivo: Exec.php Proyecto: oncesk/ssh2
 /**
  * @param ConnectionInterface $connection
  * @param CommandInterface    $command
  *
  * @return ResultInterface
  * @throws \RuntimeException
  */
 public function exec(ConnectionInterface $connection, CommandInterface $command)
 {
     $command->execBegin();
     $stream = @ssh2_exec($connection->getConnection(), $command->asString(), $command instanceof ExecCommandInterface ? $command->getPty() : null, $command->getEnv(), $command->getWidth(), $command->getHeight(), $command->getWidthHeightType());
     $connection->history()->add($command);
     if (!$stream) {
         throw new \RuntimeException(sprintf('Can not execute command `%s`', $command->asString()));
     }
     $errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
     stream_set_blocking($stream, 1);
     stream_set_blocking($errorStream, 1);
     $error = stream_get_contents($errorStream);
     $content = stream_get_contents($stream);
     fclose($errorStream);
     fclose($stream);
     if ($error) {
         $result = $this->createResult($error, true, $command);
     } else {
         $result = $this->createResult($content, false, $command);
     }
     $command->execEnd();
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * @param CommandInterface $command
  *
  * @return mixed
  */
 public function add(CommandInterface $command)
 {
     $this->history[$command->asString()] = $command;
     return $this;
 }
Ejemplo n.º 4
0
Archivo: Base.php Proyecto: oncesk/ssh2
 /**
  * @param         $result
  * @param         $isError
  * @param CommandInterface $command
  *
  * @return Result
  */
 protected function createResult($result, $isError, CommandInterface $command)
 {
     $result = new Result($result, $isError, $command);
     $command->setResult($result);
     return $result;
 }