首先按照 iconv-lite 模块
‘npm install iconv-lite’
先上代码吧:
'’String.prototype.each=function(i,fun){
var index=0;
var that=this;
while(index<=that.length){
(fun||function(){})(that.substr(index,i))
index+=i;
}
}
var exec=require(‘child_process’).exec;
var iconv=require(‘./iconv-lite’);
exec(‘ipconfig /all’,{encoding:’hex’},function(e,r){
var arr=[];
r.each(2,function(data){
arr.push(parseInt(data,16));
});
console.log(iconv.decode(new Buffer(arr), ‘GBK’))
});’’
1 首先把输出的为hex编码的字符串
2 然后把hex 转换为 buffer
3 用iconv-lite 模块把buffer 用gbk模式输出
ps:如果大家有什么好的方法 请告诉我
2 回复
String.prototype.each=function(i,fun){
var index=0;
var that=this;
while(index<=that.length){
(fun||function(){})(that.substr(index,i))
index+=i;
}
}
var exec=require('child_process').exec;
var iconv=require('./iconv-lite');
exec('ipconfig /all',{encoding:'hex'},function(e,r){
var arr=[];
r.each(2,function(data){
arr.push(parseInt(data,16));
});
console.log(iconv.decode(new Buffer(arr), 'GBK'))
});