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