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

On 5/16/07, David N. [email protected] wrote:

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

Bob S. wrote:

HTH
nohup?


Phlip
http://flea.sourceforge.net/PiglegToo_1.html

That works great, many thanks

David

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