Sha256: e20dff53ff952dbf156b6fd0d9eb317cc491ca14e7bd6414fe1490538474b49f

Contents?: true

Size: 924 Bytes

Versions: 3

Compression:

Stored size: 924 Bytes

Contents

# frozen_string_literal: true

require 'open3'
require 'log4r'
module VagrantPlugins
  module ProviderLocal
    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

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-local-0.0.3 lib/vagrant-local/util/subprocess.rb
vagrant-local-0.0.2 lib/vagrant-local/util/subprocess.rb
vagrant-local-0.0.1 lib/vagrant-local/util/subprocess.rb