Javascript event-stream.js如何引用每一行,例如(0)、(1)等

Javascript event-stream.js如何引用每一行,例如(0)、(1)等,javascript,arrays,node.js,event-stream,Javascript,Arrays,Node.js,Event Stream,好的,我在node.js脚本中有一个函数,它使用事件流模块 我可以用下面的简单脚本检查行数据,但我希望能够使用 每一行也一样。我想要的例子 line(0) --- first line of stdout line(1) --- second line of stdout ect, ect 我目前正在使用的脚本 function pinstripe() { es.pipeline( child.stdout, es.split(), es.map(func

好的,我在node.js脚本中有一个函数,它使用事件流模块

我可以用下面的简单脚本检查行数据,但我希望能够使用 每一行也一样。我想要的例子

line(0)  --- first line of stdout 
line(1)  --- second line of stdout
ect, ect
我目前正在使用的脚本

function pinstripe() {
    es.pipeline(
    child.stdout,
    es.split(),
    es.map(function (line) {
        console.log(line);
        if (line === 'Captchadone') {
        child.stdin.write("hello" + '\n');


        }

        if (line === 'Input1') {
        child.stdin.write("243534:fdghdfgth456:45365" + '\n');


        }

    })
);   
}
那我就这样叫它

pinstripe();
这就像预期的那样工作,但是我如何制作函数以便像这样使用它

function pinstripe() {
    es.pipeline(
    child.stdout,
    es.split(),
    es.map(function (line) {
        console.log(line);
        if (line === 'Captchadone') {
        child.stdin.write("hello" + '\n');
        child.stdin.write(line(0));   //i want to refrence
        child.stdin.write(line(1));   //each line like so 

        }

        if (line === 'Input1') {
        child.stdin.write("243534:fdghdfgth456:45365" + '\n');
        child.stdin.write(line(2));   //and here


        }

    })
);   
}
显然,这不起作用,但我如何才能让它起作用呢

function pinstripe() {
  var index = 0,
      lines = [];

  es.pipeline(
    child.stdout,
    es.split(),
    es.map(function (line) {
      console.log(line);
      if (index <= 2) {
        lines[index++] = line;
      }
      if (line === 'Captchadone') {
        child.stdin.write("hello" + '\n');
        child.stdin.write(lines[0]);
        child.stdin.write(lines[1]);
        // set index = 0 to start over
      }
      if (line === 'Input1') {
        child.stdin.write("243534:fdghdfgth456:45365" + '\n');
        child.stdin.write(lines[2]);
        // set index = 0 to start over
      }
    })
  );
}
函数细条纹(){
var指数=0,
行=[];
es管道(
child.stdout,
es.split(),
es.地图(功能(行){
控制台日志(行);

如果(索引)您需要将所有行保存在某个位置(例如,在数组中),以便以后引用它们。但是,这使得流式处理毫无用处……除非您保存有限数量的行(例如,根据特定模式)将其写入数组将是完美的。是否有一种方法可以将每一行推入一个数组?我现在需要的主要行是第1行第2行和第3行。不幸的是,这不起作用。我没有从[0][1]或[3]获得任何输出,但其他所有内容都是无效的there@user3407899你能把
行的内容张贴出来吗?(只需在
child.stdin.write(第[0]行)之前放置一个
console.log(第几行)