Class: Bio::Commandeer

Inherits:
Object
  • Object
show all
Defined in:
lib/bio-commandeer/commandeer.rb

Overview

See #run

Class Method Summary collapse

Class Method Details

.run(command, options = {}) ⇒ Object

Run a command line program, and be opinionated about how to handle failure

command is a string of the command to be run

  • options is a hash, with keys:

:stdin: a string that is the stdin :log: if true, turn on logging. If given an object use it as the logger



12
13
14
15
16
17
# File 'lib/bio-commandeer/commandeer.rb', line 12

def self.run(command, options={})
  obj = run_to_finish(command, options)
  obj.raise_if_failed

  return obj.stdout
end

.run_to_finish(command, options = {}) ⇒ Object

Options are as per #run, but return a CommandResult object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bio-commandeer/commandeer.rb', line 20

def self.run_to_finish(command, options={})
  if options[:log]
    if options[:log] == true
      log_name = 'bio-commandeer'
      @log = Bio::Log::LoggerPlus[log_name]
      if @log.nil? or @log.outputters.empty?
        @log = Bio::Log::LoggerPlus.new(log_name)
        Bio::Log::CLI.configure(log_name)
      end
    else
      @log = options[:log]
    end

    @log.info "Running command: #{command}"
  end
  res = CommandResult.new
  res.command = command
  res.status, res.stdout, res.stderr = systemu command, :stdin => options[:stdin]

  if @log
    @log.info "Command finished with exitstatus #{res.status.exitstatus}"
  end
  return res
end