Like the other answers, there are many ways to execute shell scripts from Ruby, but they are not all created equal. I will try to explain all the methods that I know in more detail.
Backticks
`command arg1 arg2` %x(command arg1 arg2)
Runs a command in a subshell and returns the result of the command. The command and its arguments are provided as a string limited to reverse windows. An alternative syntax is %x(...) , which helps to avoid escaping problems, for example. when you want to execute a command containing inverse elements. The brackets can be replaced with other delimiters, such as [] , {} , !! , ... to be able to get around almost any shielding problem.
Stderr is printed as usual, stdout is suppressed. Returns the output of the stdout command. This means that you can use backward exposure to get the output of the command into a variable for further processing.
Kernel.exec
exec("command arg1 arg2") exec("command", "arg1", "arg2")
Replaces the current process by running the command. The command and its arguments are provided as a regular line or as a list of lines separated by commas. It may be useful if you already have an array of arguments. The output remains as it is, i.e. It will be printed on the console as if the command was being executed directly.
Kernel.system
system("command arg1 arg2") system("command","arg1 arg2")
Like Kernel.exec , but starts up again in a subshell. Returns true if the process completed correctly (status 0), false otherwise. This works fine inside if -statements.
Kernel.spawn
pid = spawn("command")
Similar to Kernel.system , but spawns a child process to execute the specified command. Thus, the parent process does not Process.wait for the completion of the command if Process.wait is not used. The return value is the PID of the spawned process.
IO.popen
io = IO.popen("command") IO.popen("command") {|io| ... }
Repeats a command in a child process, but allows more efficient management of IO. The child processes stdout and stdin are associated with an IO object that is either available as a return value or a block parameter. If obtained via the return value, the IO object should be closed after use with io.close .