class Litterbox::Command
Attributes
process[RW]
stderr[RW]
stdout[RW]
Public Class Methods
new(cmd, log = ENV['LITTERBOX_LOG'])
click to toggle source
# File lib/litterbox/command.rb, line 5 def initialize(cmd, log = ENV['LITTERBOX_LOG']) @cmd = cmd @cmd = "sudo #{@cmd}" if ENV['USE_SUDO'] @stdout = '' @stderr = '' @log = log end
Public Instance Methods
run_command()
click to toggle source
# File lib/litterbox/command.rb, line 13 def run_command Open3.popen3(@cmd) do |_, out, err, thr| capture_stderr err capture_stdout out @process = thr.value return @stdout, @stderr, @process end end
Private Instance Methods
capture_stderr(err)
click to toggle source
# File lib/litterbox/command.rb, line 24 def capture_stderr(err) while (line = err.gets) @stderr << line unless line.nil? puts(line) if @log end end
capture_stdout(out)
click to toggle source
# File lib/litterbox/command.rb, line 31 def capture_stdout(out) while (lines = out.gets) @stdout << lines unless lines.nil? puts(lines) if @log end end