-
-
Save relistan/4183236 to your computer and use it in GitHub Desktop.
Hooking into Node.js stdout
This file contains 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
class CaptureIO | |
# Coffeescript port of: https://gist.github.com/729616 | |
# | |
# Usage: | |
# test = new CaptureIO() | |
# unhook = test.hookStdout((string, encoding, fd) -> | |
# util.debug('stdout: ' + util.inspect(string)) | |
# ) | |
# Restoring stdout: | |
# unhook() | |
hookStdout: (callback) -> | |
old_write = process.stdout.write | |
process.stdout.write = ((write) -> | |
(string, encoding, fd) -> | |
write.apply process.stdout, arguments | |
callback string, encoding, fd | |
)(process.stdout.write) | |
-> process.stdout.write = old_write |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a coffeescript port of the original JS code.