Example #1
0
 /**
  * Executo command on shell
  * @param Shell $shell
  * @return bool
  * @throws \Exception
  */
 public function run(Shell $shell)
 {
     $match = NULL;
     while (true) {
         fwrite($shell->getStream(), $this->__cmd);
         switch ($key = expect_expectl($shell->getStream(), $cases = $this->formatCases(), $match)) {
             case in_array($key, $cases):
                 // Run next
                 if ($this->__next instanceof TCommand) {
                     $this->__next->run($shell);
                 }
                 if ('break' == ($result = $this->__cases_list[$key]->proceed($shell->getStream(), $match))) {
                     break;
                 }
                 $shell->addCmd($this->__cmd);
                 $shell->addResult($this->formatResult($result));
                 return true;
                 break 2;
             case EXP_EOF:
             case EXP_FULLBUFFER:
                 break 2;
             case EXP_TIMEOUT:
                 throw new \Exception("Connection time out");
                 break 2;
             default:
                 throw new \Exception("Error has occurred!");
                 break 2;
         }
     }
     return false;
 }