Skip to content

Instantly share code, notes, and snippets.

@stringparser
Forked from pguillory/gist:729616
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stringparser/2b9e2d4ec9518ffd7d03 to your computer and use it in GitHub Desktop.
Save stringparser/2b9e2d4ec9518ffd7d03 to your computer and use it in GitHub Desktop.
var util = require('util')
function hook_stdout(callback) {
var old_write = process.stdout.write
process.stdout.write = (function(write) {
return function(string, encoding, fd) {
write.apply(process.stdout, arguments)
callback(string, encoding, fd)
}
})(process.stdout.write)
return function() {
process.stdout.write = old_write
}
}
console.log('a')
console.log('b')
var unhook = hook_stdout(function(string, encoding, fd) {
util.debug('stdout: ' + util.inspect(string))
})
console.log('c')
console.log('d')
unhook()
console.log('e')
console.log('f')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment