Created
August 9, 2012 19:50
-
-
Save wx13/3307482 to your computer and use it in GitHub Desktop.
ruby/pty interaction with octave in real-time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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