tty-process-ctl

This gem was created to enable control of interactive terminal applications. It is using pseudo tty to communicate with the process via simple API.

Example

Reading program output

Here we run ‘ls’ command and iterate its output:

TTYProcessCtl.new('ls').each do |line|
	puts line
end

Result:

Gemfile      LICENSE.txt  Rakefile     lib
Gemfile.lock README.rdoc  examples     spec

irb example

This example show how to send command to irb process. Output can be skipped with wait_until and iterated until pattern matches wit each_until.

irb = TTYProcessCtl.new('irb')

# send command
irb.send_command('2 + 2')

# wait until prompt line was printed
irb.wait_until(/:001 >/)

# print all output lines until we get to the result line (including) 
irb.each_until(/=>/) do |line|
	puts line
end

# ask irb to quit
irb.send_command('quit')

# wait irb to exit
irb.wait_exit

Result:

=> 4

Contributing to tty-process-ctl

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet.

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it.

  • Fork the project.

  • Start a feature/bugfix branch.

  • Commit and push until you are happy with your contribution.

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2012 Jakub Pastuszek. See LICENSE.txt for further details.