Considering this node.js app below:
var spawn = require('child_process').spawn,
dir = spawn('dir', ['*.txt', '/b', '/s']);
dir.stdout.on('data', function (data) {
//(A)
console.log('stdout: ' + data);
});
In (A), the on data event wait for stdout output and we can imagine that the output came 'line by line' from cmd /c dir *.txt /b /s.
But it doesn't happen. In data variable, the stdout output came with more than one line and to process something with each file path we have to split by CRLF (\r\n). Why this does happen?