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.98 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.97 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.96 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.94 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.93 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.92 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.91 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.90 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.89 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.88 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.87 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.86 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.85 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.84 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.83 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.82 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.81 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.80 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.79 lib/vagrant-zones/util/subprocess.rb
vagrant-zones-0.1.78 lib/vagrant-zones/util/subprocess.rb