Parse output of spawned node.js child process line by line

后端 未结 6 1888
旧巷少年郎
旧巷少年郎 2020-12-07 21:05

I have a PhantomJS/CasperJS script which I\'m running from within a node.js script using process.spawn(). Since CasperJS doesn\'t support require()

6条回答
  •  臣服心动
    2020-12-07 22:06

    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

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

提交回复
热议问题