Sha256: 8251b2d059dda0bfcfd0817ab094e7245435d4e14546378c9f86331f2c9a968b

Contents?: true

Size: 923 Bytes

Versions: 54

Compression:

Stored size: 923 Bytes

Contents

# frozen_string_literal: true

require 'open3'
require 'log4r'
module VagrantPlugins
  module ProviderZone
    module Util
      # This shiny device polishes bared foos
      class Subprocess
        def initialize(cmd, &_block)
          Open3.popen3(cmd) do |_stdin, stdout, stderr, thread|
            # read each stream from a new thread
            { :out => stdout, :err => stderr }.each do |key, stream|
              Thread.new do
                until (line = stream.gets).nil?
                  # yield the block depending on the stream
                  if key == :out
                    yield line, nil, thread if block_given?
                  elsif block_given?
                    yield nil, line, thread
                  end
                end
              end
            end
            thread.join # don't exit until the external process is done
          end
        end
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
vagrant-zones-0.1.77 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.76 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.75 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.73 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.72 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.71 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.70 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.69 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.67 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.66 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.65 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.64 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.63 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.62 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.61 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.60 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.59 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.58 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.57 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.56 lib/vagrant-zones/util/subprocess.rb