i did this recently to interact with ispell.  i run it twice to make the
whole process quicker, long and irrelevant story...  replace ispell with
'sh'.  the trick will be knowing how much output to grab given a line of
output.  you dont want to block reading when nothing is coming.  my example
is of a rather simple interaction.

>>

IO.popen( 'ispell -l' , "r+" ) { | spell |

	spell.puts "#{text}\n^D"
	spell.close_write()
	spell.each { |l|
		badwords << l.chomp
	}
}

badwords.uniq!

IO.popen( 'ispell -a' , "r+" ) { | spell |

        spell.gets() #version string

        badwords.each { |word|
                spell.puts word

                word_edit = spell.gets
                blank     = spell.gets

                word_edit.sub!(/.*: /, '')

                results << [word, word_edit]
        }
}

<<



-----Original Message-----
From: Alan Chen [mailto:alan / digikata.com]
Sent: Wednesday, November 07, 2001 11:09 AM
To: ruby-talk / ruby-lang.org
Subject: [ruby-talk:24529] Re: Doing both input and output to a process


On Wed, Nov 07, 2001 at 08:01:11PM +0900, HarryO wrote:
> Say I wanted to run a shell, send it commands and catch the output from
> them.
> 
> How can I do that in Ruby?  I've tried a number of access modes to popen
> and also tried running a separate thread, setting up a couple of pipes
> and setting $defin and $defout, but can't seem to get it right.
> 
> Any suggestions?

I gather that you need something more than backticks, but I thought
I'd mention them just in case.

retstr = `echo hi`

-- 
Alan Chen
Digikata LLC
alan / digikata.com
http://digikata.com