Sunday, March 27, 2011

Execute Shell Commands in Ruby

There are 3 ways in Ruby to execute Shell commands, each does it a little differently.

exec 'command'
This will execute the command and exit the Ruby script.

system 'command'
This will execute the command but you have no way to access the results. You will simply get a true or false indicating if the command was able to be executed. Call $? to get more information on the exit conditions

`command`
This will execute the command and give you access to any returned strings.

No comments:

Post a Comment