Skip to content

Instantly share code, notes, and snippets.

@czy88840616
Created February 24, 2014 03:45
Show Gist options
  • Save czy88840616/9181649 to your computer and use it in GitHub Desktop.
Save czy88840616/9181649 to your computer and use it in GitHub Desktop.
windows下exec中文处理 gbk
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'))
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment