Class: Flintlock::Runner
- Inherits:
-
Object
- Object
- Flintlock::Runner
- Defined in:
- lib/flintlock/runner.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Runner
constructor
A new instance of Runner.
- #run(command, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Runner
Returns a new instance of Runner.
5 6 7 |
# File 'lib/flintlock/runner.rb', line 5 def initialize(={}) @log = Util.load_logger(!![:debug]) end |
Instance Method Details
#run(command, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/flintlock/runner.rb', line 9 def run(command, ={}) @log.debug("running command: '#{command.inspect}'") [:capture] = !![:capture] [:env] = .fetch(:env, ENV) rout, wout = IO.pipe rerr, werr = IO.pipe pid = Process.spawn([:env], Shellwords.join(command), :out => wout, :err => werr) Process.wait(pid) status = $?.exitstatus # capture stdout/stderr wout.close werr.close stdout = rout.read stderr = rerr.read @log.linewise(stdout, :level => :info) @log.linewise(stderr) return [:capture] ? [stdout, stderr, status] : status end |