Esempio 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;
 }
Esempio n. 2
0
File: Exec.php Progetto: 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;
 }
Esempio n. 3
0
 /**
  * @param CommandInterface $command
  *
  * @return mixed
  */
 public function add(CommandInterface $command)
 {
     $this->history[$command->asString()] = $command;
     return $this;
 }
Esempio n. 4
0
File: Base.php Progetto: 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;
 }