通过 spawn 作为控制台中的起始节点?你需要在cmd中运行node js,而不是单独运行,然后通过她的团队。
var iconv = require('iconv-lite');
var fs = require('fs');
function sendData (msg) {
console.log('write msg ', msg);
cmd.stdin.write(msg + "\r\n");
}
function execCommand() {
var s = {
e : 'exec_command',
d : {
data : {}
}
};
cmd = require('child_process').spawn('cmd', ['/K']);
cmd.stdout.on('data', function (data) {
console.log(iconv.decode(data, 'cp866'))
});
cmd.stderr.on('data', function (data) {
console.log(iconv.decode(data, 'cp866'))
});
}
execCommand();
sendData('node');
sendData(' for (var i in [1,2,3]) {console.log("HAHA", i)}');