Class: Baps::Command
- Inherits:
-
Object
- Object
- Baps::Command
- Defined in:
- lib/baps/command.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#exit_status ⇒ Object
Returns the value of attribute exit_status.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(command) ⇒ Command
constructor
A new instance of Command.
- #on_stderr(data) ⇒ Object
- #on_stdout(data) ⇒ Object
Constructor Details
#initialize(command) ⇒ Command
Returns a new instance of Command.
7 8 9 10 |
# File 'lib/baps/command.rb', line 7 def initialize(command) @command = command @stdout, @stderr = String.new, String.new end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
5 6 7 |
# File 'lib/baps/command.rb', line 5 def command @command end |
#exit_status ⇒ Object
Returns the value of attribute exit_status.
5 6 7 |
# File 'lib/baps/command.rb', line 5 def exit_status @exit_status end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
5 6 7 |
# File 'lib/baps/command.rb', line 5 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
5 6 7 |
# File 'lib/baps/command.rb', line 5 def stdout @stdout end |
Instance Method Details
#execute ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/baps/command.rb', line 31 def execute puts "Executing: #{command}" Open3.popen3(command) do |_stdin, stdout, stderr, wait_thr| stdout_thread = Thread.new do while (line = stdout.gets) do on_stdout(line) end end stderr_thread = Thread.new do while (line = stderr.gets) do on_stderr(line) end end stdout_thread.join stderr_thread.join self.exit_status = wait_thr.value.to_i end end |
#on_stderr(data) ⇒ Object
16 17 18 |
# File 'lib/baps/command.rb', line 16 def on_stderr(data) @stderr += data end |
#on_stdout(data) ⇒ Object
12 13 14 |
# File 'lib/baps/command.rb', line 12 def on_stdout(data) @stdout += data end |