# Interacting with other programs

**URL:** <https://www.ruby-forum.com/t/interacting-with-other-programs/193768>\
**Category:** Ruby\
**Created:** [August 24, 2010, 3:21am UTC](https://www.ruby-forum.com/t/interacting-with-other-programs/193768 "2010-08-24T03:21:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![braas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f04885/32.png) [@braas](https://www.ruby-forum.com/u/braas)\
**Post date:** [August 24, 2010, 3:21am UTC](https://www.ruby-forum.com/t/interacting-with-other-programs/193768/1 "2010-08-24T03:21:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![braas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f04885/32.png) [@braas](https://www.ruby-forum.com/u/braas)\
**Post date:** [August 24, 2010, 3:22pm UTC](https://www.ruby-forum.com/t/interacting-with-other-programs/193768/2 "2010-08-24T15:22:33Z")

</div>

2010/8/24 Jeppe J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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](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
