Created
November 5, 2010 02:55
-
-
Save raws/663581 to your computer and use it in GitHub Desktop.
EventMachine cleverness to capture stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module EventMachine | |
| class StderrHandler < EventMachine::Connection | |
| def initialize(connection) | |
| @connection = connection | |
| end | |
| def receive_data(data) | |
| @connection.receive_stderr(data) | |
| end | |
| end | |
| def self.popen3(*args) | |
| original_stderr = $stderr.dup | |
| read, write = IO.pipe | |
| $stderr.reopen(write) | |
| connection = EM.popen(*args) | |
| $stderr.reopen(original_stderr) | |
| EM.attach(read, StderrHandler, connection) | |
| yield(connection) if block_given? | |
| connection | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment