CNode

NodeJs中文显示乱码处理:

Ssyjsky2013发布于13 年前最后回复10 年前4 回复68274 浏览0 收藏

exec('dir',{ encoding: 'utf8', timeout: 100000, maxBuffer: 200*1024, killSignal: 'SIGTERM', cwd: null, env: null }, function(error,stdout,stderr){ response.writeHead(200, {'Content-Type': 'text/plain;charset:utf-8'}); console.log(stdout); response.write(stdout); response.end(); });

输出的内容是乱码如何解决?
查看回复

回复 (4)

Z
zhs077#1·13 年前

确保js文件是utf-8

Y
yeefont#2·13 年前

var exec = require('child_process').exec; var iconv = require('iconv-lite');

exec('dir',{ encoding: 'binary', timeout: 100000, maxBuffer: 200*1024, killSignal: 'SIGTERM', cwd: null, env: null }, function(error,stdout,stderr){ var str = iconv.decode(stdout, 'GBK'); console.log(str); });

L
ldl694178563#3·13 年前

中文乱码问题也可以参考这里 http://www.9958.pw/post/nodejs_gbk

G
gengtongfei#4·10 年前
response.writeHead(200, {‘Content-Type’: ‘text/plain;charset=utf-8’});
把:改成=
参与回复
登录后即可参与回复。登录