Class: SGE::CommandRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/sge/command_runner.rb

Constant Summary collapse

SUCCESS_CODE =
0
ERROR_CODE =
1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommandRunner

Returns a new instance of CommandRunner.



10
11
12
# File 'lib/sge/command_runner.rb', line 10

def initialize
  reset!
end

Instance Attribute Details

#errputObject (readonly)

Returns the value of attribute errput.



8
9
10
# File 'lib/sge/command_runner.rb', line 8

def errput
  @errput
end

#exit_statusObject (readonly)

Returns the value of attribute exit_status.



8
9
10
# File 'lib/sge/command_runner.rb', line 8

def exit_status
  @exit_status
end

#outputObject (readonly)

Returns the value of attribute output.



8
9
10
# File 'lib/sge/command_runner.rb', line 8

def output
  @output
end

Class Method Details

.run(cmd) ⇒ Object



14
15
16
17
18
# File 'lib/sge/command_runner.rb', line 14

def self.run(cmd)
  instance = new
  instance.run(cmd)
  instance
end

Instance Method Details

#executed?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/sge/command_runner.rb', line 38

def executed?
  !!@executed
end

#reset!Object



31
32
33
34
35
36
# File 'lib/sge/command_runner.rb', line 31

def reset!
  @executed = false
  @exit_status = SUCCESS_CODE
  @output = nil
  @errput = nil
end

#run(cmd) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/sge/command_runner.rb', line 20

def run(cmd)
  reset!
  Open3.popen3(cmd) do |_, stdout, stderr, w_thread|
    @executed = true
    # Oh we assume that prior to Ruby 1.9, exit code is always success
    @exit_status = w_thread.value.exitstatus rescue SUCCESS_CODE
    @output = stdout.read.strip
    @errput = stderr.read.strip
  end
end