Ruby exec FAQ: How do I execute a shell command from a Ruby script?
It's very easy to execute an external shell command from a Ruby script. Off the top of my head there are at least two ways to do this. First, you can use the traditional backtick operators. Second, you can use the %x syntax. I'll demonstrate both examples here.
Use the backtick operator
First, I'll use the backtick operator to execute a shell command. Here's how you can run a simple command, like the ls command, using Ruby and the backtick operator: