Module: Centurion::Shell
- Defined in:
- lib/centurion/shell.rb
Class Method Summary collapse
- .echo(command) ⇒ Object
- .run_with_echo(command) ⇒ Object
- .run_without_echo(command) ⇒ Object
- .validate_status(command) ⇒ Object
Class Method Details
.echo(command) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/centurion/shell.rb', line 4 def self.echo(command) if Thread.list.find_all { |t| t.status == 'run' }.count > 1 run_without_echo(command) else run_with_echo(command) end end |
.run_with_echo(command) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/centurion/shell.rb', line 32 def self.run_with_echo(command) $stdout.sync = true $stderr.sync = true IO.popen(command) do |io| io.each_char { |char| print char } end validate_status(command) end |
.run_without_echo(command) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/centurion/shell.rb', line 12 def self.run_without_echo(command) output = Queue.new output_thread = Thread.new do while true do begin puts output.pop rescue => e info "Rescuing... #{e.}" end end end IO.popen(command) do |io| io.each_line { |line| output << line } end output_thread.kill validate_status(command) end |
.validate_status(command) ⇒ Object
41 42 43 44 45 |
# File 'lib/centurion/shell.rb', line 41 def self.validate_status(command) unless $?.success? raise "The command failed with a non-zero exit status: #{$?.exitstatus}. Command: '#{command}'" end end |