Sha256: 89e87e6a973e4cde0289d4822de4cd51d0ab279d3eb693fac361fbdcb52e64a1

Contents?: true

Size: 797 Bytes

Versions: 10

Compression:

Stored size: 797 Bytes

Contents

module IOHelper

  def self.stdin_write(data)
    r, w = IO.pipe
    old_stdin = STDIN.clone
    STDIN.reopen r
    Thread.new do
      w.write data
      w.close
    end
    begin
      yield
    ensure
      STDIN.reopen old_stdin
    end
  end

  def  self.stdout_read
    r, w = IO.pipe
    old_stdout = STDOUT.clone
    STDOUT.reopen(w)
    data = ''
    t = Thread.new do
      data << r.read
    end
    begin
      yield
    ensure
      w.close
      STDOUT.reopen(old_stdout)
    end
    t.join
    data
  end

  def  self.stderr_read
    r, w = IO.pipe
    old_stdout = STDERR.clone
    STDERR.reopen(w)
    data = ''
    t = Thread.new do
      data << r.read
    end
    begin
      yield
    ensure
      w.close
      STDERR.reopen(old_stdout)
    end
    t.join
    data
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
nedforce-sidekiq-client-cli-0.1.7 spec/support/io.rb
sidekiq-client-cli-0.1.7 spec/support/io.rb
sidekiq-client-cli-0.1.6 spec/support/io.rb
sidekiq-client-cli-0.1.5 spec/support/io.rb
sidekiq-client-cli-0.1.4 spec/support/io.rb
sidekiq-client-cli-0.1.3 spec/support/io.rb
sidekiq-client-cli-0.1.2 spec/support/io.rb
sidekiq-client-cli-0.1.1 spec/support/io.rb
sidekiq-client-cli-0.1.0 spec/support/io.rb
sidekiq-client-cli-0.0.1 spec/support/io.rb