Try this:

cspr.stdout.setEncoding('utf8');
cspr.stdout.on('data',function(data){var str = data.toString(), lines = str.split(/(\r?\n)/g);for(var i=0; i<lines.length; i++){
  // Process the line, noting it might be incomplete.}});

Note that the "data" event might not necessarily break evenly between lines of output, so a single line might span multiple data events.

发表回复