On Wed, 8 Nov 2006, James Smith wrote:

> 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.

ah.  you really need to do be able to do this then

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

sure, i think this already does everything you need:

   harp:~ > cat a.rb
   require 'open4'

   def gen_ruby_program path = 'b.rb'
     open path, 'w' do |f|
       f.write <<-src
         puts "what's your name?"
         name = gets
         puts("hi %s!" % name)
       src
     end
     path
   end

   program = gen_ruby_program

   stdin, stdout, stderr = "zaphod", "", ""
   timeout = 42

   status =
     open4.spawn "ruby #{ program }", :stdin=>stdin, :stdout=>stdout, :stderr=>stderr, :timeout=>timeout

   puts "status: #{ status.inspect }"
   puts "stdout: #{ stdout.inspect }"
   puts "stderr: #{ stderr.inspect }"
   harp:~ > ruby a.rb
   status: #<Process::Status: pid=8456,exited(0)>
   stdout: "what's your name?\nhi zaphod!\n"
   stderr: ""


if you are on windows you'll want to use systemu instead of open4.

-a
-- 
my religion is very simple.  my religion is kindness. -- the dalai lama