Class: Facter::Core::Execution::Popen3

Inherits:
Object
  • Object
show all
Defined in:
lib/facter/custom_facts/core/execution/popen3.rb

Overview

Since:

  • 2.0.0

Class Method Summary collapse

Class Method Details

.popen3e(*cmd, &block) ⇒ Object

Since:

  • 2.0.0



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/facter/custom_facts/core/execution/popen3.rb', line 29

def self.popen3e(*cmd, &block)
  opts = if cmd.last.is_a? Hash
           cmd.pop.dup
         else
           {}
         end
  in_r, in_w = IO.pipe
  opts[:in] = in_r
  in_w.sync = true
  out_r, out_w = IO.pipe
  opts[:out] = out_w
  err_r, err_w = IO.pipe
  opts[:err] = err_w
  popen_rune(cmd, opts, [in_r, out_w, err_w], [in_w, out_r, err_r], &block)
end

.popen_rune(cmd, opts, child_io, parent_io) ⇒ Object

:nodoc:

Since:

  • 2.0.0



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/facter/custom_facts/core/execution/popen3.rb', line 14

def self.popen_rune(cmd, opts, child_io, parent_io) # :nodoc:
  pid = spawn(*cmd, opts)
  child_io.each(&:close)
  result = [*parent_io, pid]
  if defined? yield
    begin
      return yield(*result)
    ensure
      parent_io.each(&:close)
      Process.wait(pid)
    end
  end
  result
end