Skip to content

Instantly share code, notes, and snippets.

@raws
Created November 5, 2010 02:55
Show Gist options
  • Select an option

  • Save raws/663581 to your computer and use it in GitHub Desktop.

Select an option

Save raws/663581 to your computer and use it in GitHub Desktop.
EventMachine cleverness to capture stderr
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