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

Sorry to beg - but can someone help me please…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs