Ruby

I would like to launch a terminal session in Linux and pass on commands using Ruby. Is this possible?
AbelaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fridomCEO/ProgrammerCommented:
Thre are  different solutions for that, in your case  you probably could use
ssh  to connect to that machine than you just send a command like:
ssh -C "ruby the_ruby_prog_file" and then ruby will run this script.

Anothersolutons could be that  you use Rush as login shell and if you are in rush you are in ruby.

And there is druby or distributed ruby
http://segment7.net/projects/ruby/drb/introduction.html

Regards
Friedrich
0
JESiiCommented:
Not sure what you mean by "pass on commands using ruby".

However, if what you're asking is to be able to issue Linux commands from a Ruby program, then there are several ways to do that.

1. You can enclose the command in "back-ticks" (the back apostrophe, which is usually in the upper left-hand corner of your keyboard under the ~ or "twiddle" key). This will execute the command and return the results to you which you can capture in a variable:

2. You can call the "system" command with varying options. It also executes the command, but with more control. Calling it with one or several parameters handles whitespace and terminal meta-characters differently. (see http://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/function.html#system and the associated exec command description for details about this).


Option 1:
  tmpvar = `ls -l`

Option 2:
  tmpvar = system("ls -l")
or
  tmpvar = system("ls","-l")

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.