unknown wrote:
> On Wed, 8 Nov 2006, James Smith wrote:
> 
>> end
>> 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
> 
> this is a terrifically bad idea, but here's how you'd do it
> 
> 
>      harp:~ > cat a.rb
>      IO.popen("ruby ruby_program.rb", "r+") do |f|
>        @read = f.gets
>        p @read
>        @write = f.puts 42
>      end
> 
>      harp:~ > cat ruby_program.rb
>      STDOUT.sync = true
> 
>      def readWrite
>        puts "printing.."
>        @string = gets
>      end
> 
>      readWrite
> 
> 
>      harp:~ > ruby a.rb
>      "printing..\n"
> 
> 
> you were calling read, which reads till the end of input and that's not 
> going
> to occur until the program exits.
> 
> i highly reccomend post exatly what you are trying to accomplish so we 
> can try
> to come up with a safer solution: spawning processes from a web-app like 
> this
> will cause problems unless you are __very__ comfortable with ipc.
> 
> cheers.
> 
> -a

Thank you very much for your comments. I am basically writing a web 
application where users can write and save ruby programs; then run them 
on the server. I am at the stage where the user can save their programs 
onto the server, however i now need to be able to input and recieve 
output from them, as well as error messages. I am fairly certain i will 
need to create a new thread for each of these processes, and probably 
have a timeout on each of them.

Any help on this would be very much appreciated. Are there any sources 
that you'd recommend me looking at?

-- 
Posted via http://www.ruby-forum.com/.