Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Buckman benbuckman

View GitHub Profile
@benbuckman
benbuckman / intercept-stdout.js
Created May 20, 2012 — forked from pguillory/gist:729616
Hooking into Node.js stdout, pipe stdout to telnet
View intercept-stdout.js
var _ = require('underscore'),
util = require('util');
// intercept stdout, passes thru callback
// also pass console.error thru stdout so it goes to callback too
// (stdout.write and stderr.write are both refs to the same stream.write function)
// returns an unhook() function, call when done intercepting
module.exports = function interceptStdout(callback) {
var old_stdout_write = process.stdout.write,
old_console_error = console.error;