/** * @param $command * @param $string */ protected function _sendCommand($command, $string) { $process = new Process($command, $this->_globalDictionary); $process->write($string); $this->_raw = $process->read(); $process->close(); }
/** * Get the terminal title. * @return string */ public static function getTitle() { if (!empty(self::$username)) { $process = new Process("uname -n"); $title = self::$username . "@" . trim($process->get()); $process->close(); return $title; } else { return "not logged shell - how cold it be possible, uh?"; } }
/** * Produce diff between the contents * * @param string left * @param string right */ protected function diff($left, $right) { with($templ = new TempFile(), $tempr = new TempFile(), $templ->open(FILE_MODE_WRITE), $tempr->open(FILE_MODE_WRITE)); $templ->write($left); $tempr->write($right); $templ->close(); $tempr->close(); // TODO: Implement "diff" in userland try { $p = new Process(sprintf('diff -u %s %s', $templ->getURI(), $tempr->getURI())); $p->in->close(); while (!$p->out->eof()) { $this->out->writeLine($p->out->readLine()); } $p->close(); } catch (IOException $e) { $this->err->writeLine('!=> Invocation of `diff` program failed.'); $templ->unlink(); $tempr->unlink(); return; } $templ->unlink(); $tempr->unlink(); }
echo '<hr>'; //$p->put(chr(21)); //var_dump($p->close()); //echo json_encode($p->getStatus()); //echo '<hr>'; // $p->put("whoami"); // $p->put(chr(13)); //echo $p->get(); usleep(500000); echo $p->get(); $p->put("whoami"); $p->put(chr(13)); echo $p->get(); echo '<hr>'; usleep(500000); echo $p->get(); echo '<hr>'; echo json_encode($p->getStatus()); echo '<hr>'; $p->put("ls -l"); $p->put(chr(13)); echo $p->get(); echo '<hr>'; usleep(500000); echo $p->get(); echo '<hr>'; usleep(500000); echo $p->get(); echo '<hr>'; echo "END " . ($p->close() ? 'NOT VALID USER OR PASSWORD' : 'SUCC LOG IN');
public function hugeStderr() { $p = new Process($this->executable(), $this->arguments('-r', 'fputs(STDERR, str_repeat("*", 65536));')); $err = ''; while (!$p->err->eof()) { $err .= $p->err->read(); } $p->close(); $this->assertEquals(65536, strlen($err)); }