Skip to content

Instantly share code, notes, and snippets.

@relistan
Forked from pguillory/gist:729616
Created December 1, 2012 16:59
Show Gist options
  • Save relistan/4183236 to your computer and use it in GitHub Desktop.
Save relistan/4183236 to your computer and use it in GitHub Desktop.
Hooking into Node.js stdout
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
@relistan
Copy link
Author

relistan commented Dec 1, 2012

This is a coffeescript port of the original JS code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment