Parent

Namespace

Methods

Class/Module Index [+]

Quicksearch

Nanoc::Extra::Piper

Public Class Methods

new(params={}) click to toggle source

@option [IO] :stdout ($stdout) @option [IO] :stderr ($stderr)

# File lib/nanoc/extra/piper.rb, line 23
def initialize(params={})
  @stdout = params.fetch(:stdout, $stdout)
  @stderr = params.fetch(:stderr, $stderr)
end

Public Instance Methods

run(cmd, input) click to toggle source

@param [Array<String>] cmd

@param [String, nil] input

# File lib/nanoc/extra/piper.rb, line 31
def run(cmd, input)
  Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thr|
    stdout_thread = Thread.new { @stdout << stdout.read }
    stderr_thread = Thread.new { @stderr << stderr.read }

    if input
      stdin << input
    end
    stdin.close

    stdout_thread.join
    stderr_thread.join

    exit_status = wait_thr.value
    if !exit_status.success?
      raise Error.new(cmd, exit_status.to_i)
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.