12

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.

Lee
  • 2,874
  • 3
  • 27
  • 51
  • Try to use data.toString('utf8'); http://stackoverflow.com/questions/12121775/convert-streamed-buffers-to-utf8-string – vanadium23 Apr 28 '15 at 08:48

1 Answers1

15

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

Miguel Mota
  • 20,135
  • 5
  • 45
  • 64