跳到主要内容
CNode

NodeJs中文显示乱码处理:

社区
Ssyjsky2013发布于 13 年前最后回复 10 年前
4683050

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)

G
gengtongfei#410 年前
response.writeHead(200, {‘Content-Type’: ‘text/plain;charset=utf-8’});
把:改成=
L
ldl694178563#313 年前

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

Y
yeefont#213 年前

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); });

Z
zhs077#113 年前

确保js文件是utf-8

参与回复

登录后即可参与回复。登录