Lee
Lee

Reputation: 2992

NodeJS child process stdout are all numbers

I'm writing some node.js scripts to kick off a child process. Code snippet is as below.

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

Script runs well except that child process's stdout and stderr prints only numeric outputs:

Sample output:

   108,34,44,34,105,110,99,114,101,97,109,101,110,116,97,108,95,112,111,108,108,105

How do I convert these numeric values to readable string?

Thanks.

Upvotes: 12

Views: 2087

Answers (1)

Miguel
Miguel

Reputation: 20633

data is an array buffer. Call its toString method JSON.stringify(data.toString('utf8'))

Upvotes: 16

Related Questions