Interacting with other programs

Is it possible to make some kind of program hook in ruby, so I can have
the program in question send it’s calls to my ruby script first, and
then have ruby forward them to the program?

If so, please throw me a link where I can read on the subject. Tried to
look into some win32API docs, but didn´t find what I was looking for.

Thanks in advance.

2010/8/24 Jeppe J. [email protected]:

Is it possible to make some kind of program hook in ruby, so I can have
the program in question send it’s calls to my ruby script first, and
then have ruby forward them to the program?

If so, please throw me a link where I can read on the subject. Tried to
look into some win32API docs, but didn´t find what I was looking for.

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/66884

You can also use #expect from the standard lib:

require ‘expect’

IO.popen “your command”, “r+” do |io|
prompt_seen = false

io.expect “>”, 100 do |line|
prompt_seen = true
printf “Got prompt: %p\n”, line
end

puts “no prompt in time!” unless prompt_seen

io.puts “exit” # for shells and other interactive programs
io.close_write
end

The code is untested but should get you going into the right direction.

Kind regards

robert