Half Shell
half_shell
is a simple ruby gem for executing shell commands
Installation:
gem install half_shell
Examples:
require 'half_shell'
# execute a command and capture the result
result = HalfShell.execute 'ls'
=> #<HalfShell::Result:0x101270f18 @stdout="Gemfile\nGemfile.lock\nREADME.md\nRakefile\nbenchmark.rb\ncoverage\nhalf_shell.gemspec\nlib\ntest\n", @status=0, @command="ls", @stderr="">
# status
result.status
=> 0
# stdout
result.stdout
=> "Gemfile\nGemfile.lock\nREADME.md\nRakefile\nbenchmark.rb\ncoverage\nhalf_shell.gemspec\nlib\ntest\n"
# stderr
result.stderr
=> ""
# raise an exception if the command exits with a non-zero status code
HalfShell.execute '(exit 123)'
=> HalfShell::ExecuteError: command <(exit 123)> failed with status <123>
# don't raise an exception if the command exits with a non-zero status code
HalfShell.execute '(exit 123)', :raise => false
=> #<HalfShell::Result:0x1012380a0 @stdout="", @status=123, @command="(exit 123)", @stderr="">
# execute a command, but only care about the status
HalfShell.execute! 'ls'
=> true
HalfShell.execute! '(exit 123)'
=> false