Class: Litterbox::Command
- Inherits:
-
Object
- Object
- Litterbox::Command
- Defined in:
- lib/litterbox/command.rb
Overview
CLI Command operations
Instance Attribute Summary collapse
-
#process ⇒ Object
Returns the value of attribute process.
-
#stderr ⇒ Object
Returns the value of attribute stderr.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
Instance Method Summary collapse
-
#initialize(cmd) ⇒ Command
constructor
A new instance of Command.
- #run_command ⇒ Object
Constructor Details
#initialize(cmd) ⇒ Command
Returns a new instance of Command
5 6 7 8 9 10 |
# File 'lib/litterbox/command.rb', line 5 def initialize(cmd) @cmd = cmd @cmd = "sudo #{@cmd}" if ENV['USE_SUDO'] @stdout = '' @stderr = '' end |
Instance Attribute Details
#process ⇒ Object
Returns the value of attribute process
4 5 6 |
# File 'lib/litterbox/command.rb', line 4 def process @process end |
#stderr ⇒ Object
Returns the value of attribute stderr
4 5 6 |
# File 'lib/litterbox/command.rb', line 4 def stderr @stderr end |
#stdout ⇒ Object
Returns the value of attribute stdout
4 5 6 |
# File 'lib/litterbox/command.rb', line 4 def stdout @stdout end |
Instance Method Details
#run_command ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/litterbox/command.rb', line 12 def run_command Open3.popen3(@cmd) do |_, out, err, thr| while (line = err.gets) @stderr << line unless line.nil? puts(line) end while (lines = out.gets) @stdout << lines unless lines.nil? puts(lines) end @process = thr.value return @stdout, @stderr, @process end end |