From: "yermej@..." Date: 2007-09-25T07:10:04+09:00 Subject: Re: communicating w/ command-line program (OR ruby expect) On Sep 24, 4:57 pm, "Cameron Matheson" wrote: > Hello, > > I'm trying to communicate w/ a command-line process w/ ruby. I > thought IO.popen would be the right tool for the job, but I need to be > able to read and write to the process, and I can't get it to work > (i've googled for examples, but everything I have seen is only doing > one-way communication). Anyway, it looks like what I need is > something like "Expect" for ruby. Does anyone know if such a tool > exists? (Or any other way in which I could read/write from a > command-line program). > > Thanks! > Cam If you're just calling a command line tool like grep or something (reads standard input and then returns result to standard out), IO.popen is what you need: cmd_output = IO.popen "cmd -args some stuff", 'r+' do |pipe| pipe.write the_input pipe.close_write pipe.read.chomp end if $? == 0 # success, do something else # cmd exited with an error, deal with it end If you need to interact with something (a la irb, ftp, telnet, etc.) you'll need to find something else, I think. Jeremy