File: capture_output_helper.rb

package info (click to toggle)
rake-compiler 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 324 kB
  • sloc: ruby: 1,497; makefile: 3
file content (22 lines) | stat: -rw-r--r-- 411 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module CaptureOutputHelper
  def capture_output(&block)
    old_stdout = $stdout
    old_stderr = $stderr

    stream_out = StringIO.new
    stream_err = StringIO.new

    begin
      $stdout = stream_out
      $stderr = stream_err
      yield
    ensure
      $stdout = old_stdout
      $stderr = old_stderr
    end
    stream_out.rewind
    stream_err.rewind

    [stream_out.read, stream_err.read]
  end
end