发布时间:2022-08-09 文章分类:编程知识 投稿人:李佳 字号: 默认 | | 超大 打印

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.