簡體   English   中英

event-stream.js我如何引用每行IE(0),(1)等

[英]event-stream.js how can i refrence each line I.E (0) , (1) ect ect

好的,我在使用事件流模塊的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
      }
    })
  );
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM