NodeJS 调用 Python 模块输出乱码问题

NodeJS 调用 Python 模块输出乱码问题

在 node 服务中使用 ipc 方式和 python 模块通讯,python进程返回的中文内容在 node 中输出会出现乱码问题(通常是 window 系统下),可以使用 iconv-lite 库去解码:

const engineWorker = cp.spawn(execPath, execArgs, { encoding: 'utf-8' })
engineWorker.stdout.on('data', function(data) {
  workerOutput += isWin ? iconv.decode(data, 'gbk') : data
})
posted @ 2022-01-17 17:50  孤喵自赏  阅读(505)  评论(0)    收藏  举报