Expectr is an API to the functionality of Expect (see expect.nist.gov/) implemented in ruby.

Using Expectr

Effort is taken to make implementation as simple as possible.


Implementation of task automation should be relatively straightforward. A lightweight application might look similar to the following:

# myapp.rb
require 'expectr'

exp = Expectr.new( '/bin/bash', flush_buffer: false )
exp.send( "ls\n" )
match = exp.expect( %r{bash} ) # => MatchData
match = exp.expect( "this shouldn't match anything" ) # raises Timeout::Error


It is possible to allow a user to interact directly with an Expectr object as with the Expect functionality in TCL

# logmein.rb
require 'expectr'

ssh = { host: 'example.com', user: 'example', pass: 'password' }
exp = Expectr.new( "ssh #{ssh[:user]}@#{ssh[:host]}" )
exp.expect( %r{#{ssh[:user]}@#{ssh[:host]}'s password:} )
ssh.send( ssh[:pass] + "\n" )



Effort is made to keep external requirements to a minimum. As such, presently there are no external requirements for development. If you want to contribute, please:

* Fork the project.
* Make a branch for your contribution if it's more than a simple fix.
* Add tests for new functionality.
* Send me a pull request on Github

Copyright © 2012 Chris Wuest. See LICENSE for details.