running a shell command in the background from Rails

Hi

I need to call a method on one of my models in response to a form being submitted that may take quite some time to run. I'd like to just use script/runner and have it run in the background returning immediately. The following seems like it should work but instead it waits for the command to finish:

    `#{RAILS_ROOT}/script/runner \"Project.my_method\" &`

With the '&' it returns immediately when run from the terminal but not when called from Rails.

I've had a look at backgroundrb but that seems far too complicated for the simple thing I'm trying to achieve. Is there a way I can run a shell command like this but have it return immediately?

David North

Try using system() instead of backticks, and be sure to redirect stderr and stdout to a file or to /dev/null.

   system "#{RAILS_ROOT}/script/runner Project.my_method >/dev/null 2>&1 &"

HTH

Bob Showalter wrote:

    `#{RAILS_ROOT}/script/runner \"Project.my_method\" &`

With the '&' it returns immediately when run from the terminal but not when called from Rails.

Try using system() instead of backticks, and be sure to redirect stderr and stdout to a file or to /dev/null.

  system "#{RAILS_ROOT}/script/runner Project.my_method >/dev/null 2>&1 &"

HTH

nohup?

That works great, many thanks

David