petemo94-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
2007-Oct-22 17:16 UTC
How to Execute simple Linux Command from controller?
Folks, I am new to rails and have not found out how to do this. What I am trying to do is execute a Linux command from one of my controllers. For example, I''ve tried these 2 methods. Both result in a the web-page to hang forever. I get NO response back. The question I have is, how do I execute a Linux command and then parse the output from this command to take further action. Much appreciated. def restore1 render_text `uname -a` end or def restore2 io = IO.popen("uname -a") output = io.read io.close end Pete M. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
John Topley
2007-Oct-22 19:16 UTC
Re: How to Execute simple Linux Command from controller?
Not sure if this will help, but render_text is deprecated. Try using render :text => `uname -a` I have successfully been able to execute shell commands and get the results back from within a Rails app, but I put them in a separate model class and returned the results in a method. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Shai Rosenfeld
2007-Oct-23 13:46 UTC
Re: How to Execute simple Linux Command from controller?
petemo94-/E1597aS9LQAvxtiuMwx3w@public.gmane.org wrote:> Folks, > > I am new to rails and have not found out how to do this. What I am > trying to do is execute a Linux command from one of my controllers. > For example, I''ve tried these 2 methods. Both result in a the web-page > to hang forever. I get NO response back. > > The question I have is, how do I execute a Linux command and then > parse the output from this command to take further action. Much > appreciated. > > def restore1 > render_text `uname -a` > end > > or > > def restore2 > io = IO.popen("uname -a") > output = io.read > io.close > end > > Pete M.u may need to require + include the file into the controller before being able to use it''s functionalities, ie: require ''io'' class ExController include IO # now i can use the io.rb file''s methods :) end (the above very untested, i''m not sure exactly what file needs to be included, but this is the idea) hope it helps :p -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---