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.55 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.54 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.52 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.48 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.46 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.44 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.12 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.10 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.9 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.8 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.41 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.3 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.0.12 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.0.1 lib/vagrant-zones/util/subprocess.rb