I want to use PTY.spawn(some shell program) and then use expect method
to decide what should be inputed next step.
But my shell program output is not fixed. It depends on the
environment on which it runs. So my question is, does ruby support
multiple expect?
If so, my code can be like:
PTY.spawn(my shell program) do |reader, writer, pid|
reader.expect(/a|b/) do |str|
if str.match(/a/)
do something
else
do something else
end
end
Well I just looked at the source, and you can do exactly this. In
fact, expect does you one better, if you use groups in your regexp it
yields you those two
e.g.
reader.expect(/(a|b|c)e/) do |whole_string, first_group,
second_group, etc|
Well I just looked at the source, and you can do exactly this. In
fact, expect does you one better, if you use groups in your regexp it
yields you those two
e.g.
reader.expect(/(a|b|c)e/) do |whole_string, first_group,
second_group, etc|
...
end
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.