7
我在写一些node.js脚本来启动子进程。代码片段如下。NodeJS子进程stdout都是数字
var spawn = require('child_process').spawn;
var child = spawn ('node', ['script.js'])
child.stdout.on('data',
function (data) {
logger.verbose('tail output: ' + JSON.stringify(data));
}
);
child.stderr.on('data',
function (data) {
logger.error('err data: ' + data);
}
);
脚本运行良好,除了子进程的输出和错误只打印输出数值:
输出示例:
108,34,44,34,105,110,99,114,101,97,109,101,110,116,97,108,95,112,111,108,108,105
如何将这些数值转换为可读的字符串?
谢谢。
尝试使用data.toString('utf8'); http://stackoverflow.com/questions/12121775/convert-streamed-buffers-to-utf8-string – vanadium23