Class: SGE::CommandRunner
- Inherits:
-
Object
- Object
- SGE::CommandRunner
- Defined in:
- lib/sge/command_runner.rb
Constant Summary collapse
- SUCCESS_CODE =
0
- ERROR_CODE =
1
Instance Attribute Summary collapse
-
#errput ⇒ Object
readonly
Returns the value of attribute errput.
-
#exit_status ⇒ Object
readonly
Returns the value of attribute exit_status.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Class Method Summary collapse
Instance Method Summary collapse
- #executed? ⇒ Boolean
-
#initialize ⇒ CommandRunner
constructor
A new instance of CommandRunner.
- #reset! ⇒ Object
- #run(cmd) ⇒ Object
Constructor Details
#initialize ⇒ CommandRunner
Returns a new instance of CommandRunner.
10 11 12 |
# File 'lib/sge/command_runner.rb', line 10 def initialize reset! end |
Instance Attribute Details
#errput ⇒ Object (readonly)
Returns the value of attribute errput.
8 9 10 |
# File 'lib/sge/command_runner.rb', line 8 def errput @errput end |
#exit_status ⇒ Object (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 |
#output ⇒ Object (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
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 |