0.0
No commit activity in last 3 years
No release in over 3 years
A dead simple method of running shell commands from within Ruby, by applying opinion
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
~> 2.0
~> 5.0
~> 3.2

Runtime

~> 2.6
 Project Readme

bio-commandeer

Build Status

Bio::Commandeer provides a dead simple method of running shell commands from within Ruby:

require 'bio-commandeer'
Bio::Commandeer.run 'echo 5' #=> "5\n"

The real advantage of bio-commandeer is that when something goes wrong, it tells you; you don't have go looking for the error. Take for instance this simple script:

#!/usr/bin/env ruby
require 'bio-commandeer'
print Bio::Commandeer.run('echo 5')
print Bio::Commandeer.run('cat /not_a_file')

The output is:

5
<snip>/lib/bio-commandeer/commandeer.rb:32:in `run': Command returned non-zero exit status (1), likely indicating failure. Command run was cat /not_a_file and the STDERR was: (Bio::CommandFailedException)
cat: /not_a_file: No such file or directory
	from spec/eg.rb:4:in `<main>'

When a command fails (as detected through a non-zero exit status), then a Bio::CommandFailedException exception is thrown. While you can catch these exceptions with begin/rescue, often the best to do is fail, especially if you are writing quick one-off scripts.

Of course, when running commands such as this, take care not to trust the input directly from the command line, and especially not from a website. When in doubt, use inspect around the arguments to make sure that you don't run into little bobby tables.

Note: this software is under active development! Currently it is perhaps overly opinionated and as such not overly flexible.

Logging

Commands run are logged with level info, if requested:

require 'bio-commandeer'
Bio::Log::CLI.logger("stderr"); Bio::Log::CLI.trace("info");
puts Bio::Commandeer.run 'echo 5', :log=>true

On stderr this gives

 INFO bio-commandeer: Running command: echo 5
 INFO bio-commandeer: Command finished with exitstatus 0

Or a logging can be given directly, so long as it has an info method:

Bio::Commandeer.run 'echo 5', :log=>my_logger

A command can also be run to completion without raising an errors using run_to_finish:

require 'bio-commandeer'
result = Bio::Commandeer.run_to_finish 'echo 5' #=> Bio::CommandResult
result.stdout #=> "5\n"

Installation

gem install bio-commandeer

Biogems.info

This Biogem is published at (http://biogems.info/index.html#bio-commandeer)

Copyright

Copyright (c) 2014-2015 Ben J. Woodcroft. See LICENSE.txt for further details.