I wonder if anyone knows how to run Unix/Linux commands from Ruby? I understand that the Perl counterpart could be sth like the following. * First I create a perl file example.pl * Then inside the file I have the desired Linux commands. #!/usr/local/bin/perl -w `ls -l`; `curl google.com`; * When I run the file, those Linux commands would be executed. Just wonder how I can do this in Ruby in Linux environment. Thanks a lot! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 20 Feb 2008, at 17:03, newbie wrote:> > I wonder if anyone knows how to run Unix/Linux commands from Ruby? > > I understand that the Perl counterpart could be sth like the > following. > > * First I create a perl file example.pl > > * Then inside the file I have the desired Linux commands. > > #!/usr/local/bin/perl -w > `ls -l`; > `curl google.com`; > > * When I run the file, those Linux commands would be executed. > > Just wonder how I can do this in Ruby in Linux environment. Thanks a > lot!exactly the same: by enclosing the command in backticks (`) you''ll get the output produced as the return value, and the exit code is in $? Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Very nice. Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---