• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 567
  • Last Modified:


I would like to launch a terminal session in Linux and pass on commands using Ruby. Is this possible?
2 Solutions
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

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")
  tmpvar = system("ls","-l")

Open in new window


Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now