Topic: Reading and Writing to an external program

Hi,

I would basically like to be able to run a ruby program from my rails
application and be able to read from it and write to it accordingly.

OK, i am currently using:

IO.popen("ruby ruby_program.rb", "r+") do |f|
@read = f.read
@write = f.write  #this is where i need help
end

say if the external ruby program was as follows:

0  def readWrite
1  puts "printing.."
2  @string = gets
3  end
4  readWrite

I can currently read (in example) "printing..", however when it reaches
line 2 of the ruby program, i can't seem to write to it, and my rails
program just waits. I need to use something that says "read from program
until it is waiting for input, and then write to it" (also, when writing
to the program, how do i emulate the user pressing enter - \n? )

Thanks

Re: Reading and Writing to an external program

That's kinda tricky.  Hopefully somebody with a better knowledge of Ruby's IO capabilities can jump in here.

It would be much easier though if you simply included the Ruby file.  You can set up some parameters to 'send' to whatever classes or modules appear in the ruby file and still be able to do the same work.