Skip to content

Instantly share code, notes, and snippets.

@wx13
Created August 9, 2012 19:50
Show Gist options
  • Save wx13/3307482 to your computer and use it in GitHub Desktop.
Save wx13/3307482 to your computer and use it in GitHub Desktop.
ruby/pty interaction with octave in real-time
require 'pty'
def till_prompt(cout)
buffer = ""
loop { buffer << cout.getc.chr; break if buffer =~ /octave:.*>/ }
return buffer
end
def octave(string)
@octave_in.printf("#{string}\n")
puts till_prompt(@octave_out)
end
@octave_out, @octave_in, @pid = PTY.spawn("octave")
printf till_prompt(@octave_out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment