Created
April 2, 2012 18:10
-
-
Save piscisaureus/2285907 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var capture = ""; | |
var cmd = require('child_process').spawn('cmd'); | |
process.stdin.pipe(cmd.stdin); | |
cmd.stdout.pipe(process.stdout); | |
cmd.stderr.pipe(process.stderr); | |
cmd.stdout.on('data', function(data) { | |
capture += data.toString(); | |
}); | |
cmd.stderr.on('data', function(data) { | |
capture += data.toString(); | |
}); | |
/* Enable two lines if you want to try out with raw mode. * | |
/* Note that use should then use ctrl+enter instead of enter. */ | |
/* | |
process.stdin.pipe(process.stdout); | |
require('tty').setRawMode(true); | |
process.stdin.on('data', function(data) { | |
capture += data.toString(); | |
}); | |
*/ | |
process.stdin.resume(); | |
cmd.on('exit', function() { | |
console.log("-----------------\n"); | |
console.log("Captured content:\n"); | |
console.log(capture); | |
console.log("-----------------\n"); | |
process.stdin.pause(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment