I am using Open3\'s popen3 method to start a process that functions in a console-like / REPL fashion to repeatedly accept input and return output.
I am able to open
You can have some success using expect
library, and have the child process to explicitly mark the end of each output, like:
require 'expect'
require 'open3'
Open3.popen3("/bin/bash") do
| input, output, error, wait_thr |
input.sync = true
output.sync = true
input.puts "ls /tmp"
input.puts "echo '----'"
puts output.expect("----", 5)
input.puts "cal apr 2014"
input.puts "echo '----'"
puts output.expect("----", 5)
end
As a bonus, expect
has a timeout
option.