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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bob Showalter
2007-May-17 00:49 UTC
Re: running a shell command in the background from Rails
On 5/16/07, David North <davidnorth-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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.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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 &" > > HTHnohup? -- Phlip http://flea.sourceforge.net/PiglegToo_1.html --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
David North
2007-May-18 08:38 UTC
Re: running a shell command in the background from Rails
That works great, many thanks David On May 17, 1:49 am, "Bob Showalter" <showa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 5/16/07, David North <davidno...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > 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. > > 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---