2017 © Pedro PelĂĄez
 

library expect

Allows to interact with processes through PTY.

image

smalot/expect

Allows to interact with processes through PTY.

  • Friday, March 20, 2015
  • by smalot
  • Repository
  • 1 Watchers
  • 1 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Expect

Use of 'proc_open' to simulate expect behavior. That's a mix between 'expect' command line tool and the PHP library: http://php.net/manual/fr/book.expect.php, (*1)

Sample code

open('telnet 192.168.59.103 4002');

while (1) {
    switch ($expect->expect(
      array(
        'escape'       => array('/.*Escape character.*\n/mis', Expect::EXP_REGEXP),
        'command line' => array('/.+#/', Expect::EXP_REGEXP),
      ),
      $match
    )) {
        case 'escape':
            var_dump('escape', $match);
            $expect->write('');
            break;

        case 'command line':
            var_dump('command line', $match);
            $expect->write('show cdp');
            break 2;

        case Expect::EXP_TIMEOUT:
            die('timeout');

        case Expect::EXP_EOL:
            die('eol');
    }
}

while (1) {
    switch ($expect->expect(
      array(
        'command line' => array('/(.*)[\r\n]+([^\n]+#)/mis', Expect::EXP_REGEXP),
      ),
      $match
    )) {
        case 'command line':
            var_dump('result', $match);
            break 2;

        case Expect::EXP_TIMEOUT:
            die('timeout');

        case Expect::EXP_EOL:
            die('eol');
    }
}



$expect->close();


?>

The Versions

20/03 2015

dev-master

9999999-dev

Allows to interact with processes through PTY.

  Sources   Download

MIT

20/03 2015

v0.1

0.1.0.0

Allows to interact with processes through PTY.

  Sources   Download

MIT