You can do this by placing the pipe in the readline. Here's an example, using a cycle whileof documentation ri readline, which simply sends command 1, command2, command 3to readline.
require 'readline'
rd, wr = IO.pipe
(1..3).each do |i|
wr.puts "command #{i}"
end
wr.close
Readline.input = rd
while buf = Readline.readline('', true)
p Readline::HISTORY.to_a
print("-> ", buf, "\n")
end
Conclusion:
["command 1"]
-> command 1
["command 1", "command 2"]
-> command 2
["command 1", "command 2", "command 3"]
-> command 3
source
share