How do I use ruby expect to feed input to a simple bash script? Here
is a minimal example of what I’m trying to do. All help appreciated.
First, the simple bash script. When run from the command line it
performs as I expect.
#!/bin/bash
echo “1) red”
echo “2) blue”
echo “3) green”
echo "#? "
read CHOICE
sleep 5
echo “$CHOICE is done”
exit 0
Now for the ruby script I want to work with the bash script
#!/usr/bin/env ruby
require ‘expect’
require ‘pty’
p = PTY.spawn(’./simple’) do |read,write,pid|
write.sync = true
read.sync = true
$expect_verbose = true # shows actions on screen
read.expect("#? ") {write.puts “3”}
end
When ruby operates the bash script, I doesn’t seem like the input is
given to bash.
I’ve tried ruby 1.8.4 on OSX and ruby 1.8.5 on Fedora Core 6.