Skip to content

Instantly share code, notes, and snippets.

@gsamokovarov
Created August 7, 2013 18:54
Show Gist options
  • Save gsamokovarov/6177264 to your computer and use it in GitHub Desktop.
Save gsamokovarov/6177264 to your computer and use it in GitHub Desktop.
PTY.spawn attaches a psuedo-terminal device to the standard input.
require 'pty'
PTY.spawn 'irb' do |output, input, pid|
loop do sleep 1
input.puts 'puts :Wootz!'
puts output.gets
end
end
__END__
irb(main):001:0> puts :Wootz!
Wootz!
=> nil
irb(main):002:0> puts :Wootz!
Wootz!
=> nil
irb(main):003:0> puts :Wootz!
Wootz!
^Cconsole.rb:4:in `sleep': Interrupt
from console.rb:4:in `block (2 levels) in <main>'
from console.rb:4:in `loop'
from console.rb:4:in `block in <main>'
from console.rb:3:in `spawn'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment