Module: FlazmRubyHelpers::Os
- Defined in:
- lib/flazm_ruby_helpers/os.rb
Class Method Summary collapse
Class Method Details
.exec(command, stream: true) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/flazm_ruby_helpers/os.rb', line 9 def self.exec(command, stream: true) output = [] ; threads = [] ; status = nil Open3.popen3(command) do |_stdin, stdout, stderr, wait_thr| { out: stdout, err: stderr }.each do |_key, stream| threads << Thread.new do until (raw_line = stream.gets).nil? output << raw_line.to_s puts raw_line.to_s if stream end end end threads.each(&:join) status = wait_thr.value.success? end return output, status end |