Module: Rtasklib::Execute
Overview
How to execute shell commands and capture output
Constant Summary
- DEBUG =
When true writes all shell commands to STDERR
false
Instance Method Summary (collapse)
-
- (Object) each_popen3(program = 'task', *opts, &block) {|l, i, o, e, t| ... }
Same as Execute#popen3, but yields each line of input.
-
- (Object) handle_response(stdout, stderr, thread)
Default error handling called in every popen3 call.
-
- (Object) popen3(program = 'task', *opts, &block) {|i, o, e, t| ... }
Use Open3#popen3 to execute a unix program with an array of options and an optional block to handle the response.
-
- (Object) task_each_popen3(*opts, &block) {|l, i, o, e, t| ... }
Same as Execute#each_popen3, but calls it with the 'task' program.
-
- (Object) task_popen3(*opts, &block) {|i, o, e, t| ... }
Same as Execute#popen3, only defaults to using the 'task' program for convenience.
Instance Method Details
- (Object) each_popen3(program = 'task', *opts, &block) {|l, i, o, e, t| ... }
Same as Execute#popen3, but yields each line of input
66 67 68 69 70 71 72 |
# File 'lib/rtasklib/execute.rb', line 66 def each_popen3 program='task', *opts, &block popen3(program, *opts) do |i, o, e, t| o.each_line do |l| yield(l, i, o, e, t) end end end |
- (Object) handle_response(stdout, stderr, thread)
Default error handling called in every popen3 call. Only executes if thread had a failing exit code
91 92 93 94 95 96 |
# File 'lib/rtasklib/execute.rb', line 91 def handle_response stdout, stderr, thread unless thread.value.success? dump = "#{thread.value} \n Stderr: #{stderr.read} \n Stdout: #{stdout.read} \n" raise dump end end |
- (Object) popen3(program = 'task', *opts, &block) {|i, o, e, t| ... }
Use Open3#popen3 to execute a unix program with an array of options and an optional block to handle the response.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rtasklib/execute.rb', line 31 def popen3 program='task', *opts, &block execute = opts.unshift(program) execute = execute.join(" ") warn execute if DEBUG Open3.popen3(execute) do |i, o, e, t| handle_response(o, e, t) yield(i, o, e, t) if block_given? end end |
- (Object) task_each_popen3(*opts, &block) {|l, i, o, e, t| ... }
Same as Execute#each_popen3, but calls it with the 'task' program
81 82 83 84 85 |
# File 'lib/rtasklib/execute.rb', line 81 def task_each_popen3 *opts, &block each_popen3("task", *opts) do |l, i, o, e, t| yield(l, i, o, e, t) end end |
- (Object) task_popen3(*opts, &block) {|i, o, e, t| ... }
Same as Execute#popen3, only defaults to using the 'task' program for convenience.
54 55 56 |
# File 'lib/rtasklib/execute.rb', line 54 def task_popen3 *opts, &block popen3('task', opts, &block) end |