Welcome to ExecuteShell
ExecuteShell provides cross-platform shell command execution. Linux, Windows, and Mac OS X are currently supported. In other words, it lays the smack down like a hungry t-rex in the octagon with a pig.
Getting Started
Install ExecuteShell at the command prompt if you haven't yet:
$ gem install execute_shell
Require the gem in your Gemfile:
gem 'execute_shell', '~> 1.0.2'
Require the gem wherever you need to use it:
require 'execute_shell'
Usage
Simply call ExecuteShell.run as needed:
result = ExecuteShell.run('ls ~')
In this example, result will be a ShellResult object containing information regarding the executed command.
Available methods include:
out ...... Standard out.
err ...... Standard error.
success? . Whether the command was executed successfully.
to_s ..... Standard out and standard error concatenated.
If you wish to simply get a single success, output, or error value back, you may use calls such as:
ExecuteShell.run_success?('ls ~')
ExecuteShell.run_out('ls ~')
ExecuteShell.run_err('ls ~')
ExecuteShell.run_to_s('ls ~')
These may be chained together and will be returned in an array in the order they are specified:
ExecuteShell.run_out_err('ls ~')
ExecuteShell.run_to_s_success_out('ls ~')
ExecuteShell.run_err_out_success('ls ~')
Additional Notes
The run method has a second optional parameter, which is a path. If specified, the working directory will be changed to this path prior to executing the shell command. It will be set back to the original working directory before returning to the calling function.
Success is based on the content of the err attribute of ShellResult.
Additional Documentation
$ gem install yard
$ yard
Or:
$ rake rdoc:app
License
ExecuteShell is released under the LGPLv3 license.