问:
Why do I have so many Docker images with REPOSITORY name = <none>?
When I type the command docker images to display the images I have the following:

```<code>REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
rhel-httpd              latest              fbf8d1f684c2        17 hours ago        21.1MB
<none>                  <none>              8e78b0845d65        17 hours ago        21.1MB
<none>                  <none>              facd9f65febe        17 hours ago        21.1MB
<none>                  <none>              c0aa5de96c38        17 hours ago        21.1MB
express-mongo           latest              cbb3272e59e6        18 hours ago        21.1MB
<none>                  <none>              ad2d7dce3f31        18 hours ago        427MB
<none>                  <none>              a21766b25c6e        18 hours ago        1.08GB
express-mongo           latest              8a389964a9da        18 hours ago        933MB
react                   app                 0fdb29acba70        18 hours ago        1.08GB
api_web                 latest              2a36a4ae57a4        19 hours ago        933MB
<none>                  <none>              e36940791278        20 hours ago        1.03GB
<none>                  <none>              24bc73878199        20 hours ago        1.46GB
<none>                  <none>              a35acb3d26f3        20 hours ago        1.03GB
<none>                  <none>              78d1cc9c676a        21 hours ago        1.03GB
<none>                  <none>              b79a74a0663c        21 hours ago        1.46GB
<none>                  <none>              fd398d636305        21 hours ago        1.46GB
<none>                  <none>              459cc063b63c        21 hours ago        1.03GB
<none>                  <none>              cfa5dca23e0c        22 hours ago        1.03GB
<none>                  <none>              35f67b8276a0        23 hours ago        1.46GB

</code>```

Where do these come from?

Should I be deleting them it looks like they are taking up significant size?

Thank you.

答:
They are the intermediate layers(images) that you build using dockerfile. Inorder to save just the final layer, you can add rm intermediate images parameter

i.e docker build --force-rm ...(other parameters)  while building the docker image

Also docker image prune removes these intermediate images.

Body:
When I type the command docker images to display the images I have the following:

REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
rhel-httpd              latest              fbf8d1f684c2        17 hours ago        21.1MB
<none>                  <none>              8e78b0845d65        17 hours ago        21.1MB
<none>                  <none>              facd9f65febe        17 hours ago        21.1MB
<none>                  <none>              c0aa5de96c38        17 hours ago        21.1MB
express-mongo           latest              cbb3272e59e6        18 hours ago        21.1MB
<none>                  <none>              ad2d7dce3f31        18 hours ago        427MB
<none>                  <none>              a21766b25c6e        18 hours ago        1.08GB
express-mongo           latest              8a389964a9da        18 hours ago        933MB
react                   app                 0fdb29acba70        18 hours ago        1.08GB
api_web                 latest              2a36a4ae57a4        19 hours ago        933MB
<none>                  <none>              e36940791278        20 hours ago        1.03GB
<none>                  <none>              24bc73878199        20 hours ago        1.46GB
<none>                  <none>              a35acb3d26f3        20 hours ago        1.03GB
<none>                  <none>              78d1cc9c676a        21 hours ago        1.03GB
<none>                  <none>              b79a74a0663c        21 hours ago        1.46GB
<none>                  <none>              fd398d636305        21 hours ago        1.46GB
<none>                  <none>              459cc063b63c        21 hours ago        1.03GB
<none>                  <none>              cfa5dca23e0c        22 hours ago        1.03GB
<none>                  <none>              35f67b8276a0        23 hours ago        1.46GB

Where do these come from?

Should I be deleting them it looks like they are taking up significant size?

Thank you.


来源: stackexchange

问:
JSON.parse(e.data) - websocket's onmessage - ReferenceError: e is not defined / 'data' of undefined / WebSocket is already in CLOSING or CLOSED state
websocket/JSON newbie here. I have an issue with receiving data from function event. Could somebody help me?

Looks like the message is send properly to the server (correct message_cart value while using sendMessage() function), but issues while receiving data.

My console:

websocket.min.js:35 Uncaught TypeError: Cannot read property 'data' of
  undefined
      at receiveMessage (websocket.min.js:35)

message from cart to server: 10 // the number is correct

websocket.min.js:83 WebSocket is already in CLOSING or CLOSED state.

My websocket.js:

```<code>document.addEventListener('DOMContentLoaded', function(){
  'use strict';

  var ws_protocol = 'ws://';
  if (window.location.protocol == "https:")
    ws_protocol = 'wss://';
  var ws_url = ws_protocol + window.location.host + '/ws/auctions/' + qs;
  var webSocket = new WebSocket(ws_url);

  var amountbutton = document.getElementsByClassName('amountButton');
  var message_cart;

  webSocket.onopen = sendMessage();
  webSocket.onmessage = receiveMessage();

  function receiveMessage(e) {
    var msgData = JSON.parse(e.data);
    if ('auction_data' in msgData) {
        console.log("here we are, 'auction_data' in msgData");
    } else if ('cart_data' in msgData) {
        console.log("here we are, 'cart_data' in msgData");
    }
  };

  function sendMessage() {

    for(let i = 0; i < amountbutton.length; i++) {

      amountbutton[i].onclick = (e) => {
        if(!amountbutton[i].nextElementSibling) {
          message_cart = amountbutton[i].previousElementSibling.value;
          message_cart++;
        } else {
          message_cart = amountbutton[i].nextElementSibling.value;
          message_cart--;
        }
        console.log("message from cart to server: " + message_cart);
        webSocket.send(message_cart);
      }
    }
  }

  webSocket.onclose = function(e) {
    console.error('Websocket closed.');
  };

}, false);
</code>```

答:
In order for web socket to call your onopen and onmessage callbacks, you must assign them to listeners as a function, not as values these function are returning. So the solution is to just assign these functions without calling them, like that:

```<code>  webSocket.onopen = sendMessage; // <- no curly braces in there
  webSocket.onmessage = receiveMessage; // <- no curly braces in there
</code>```

Hope it helps :)

ContentLicense: CC BY-SA 4.0

Body:
websocket/JSON newbie here. I have an issue with receiving data from function event. Could somebody help me?

Looks like the message is send properly to the server (correct message_cart value while using sendMessage() function), but issues while receiving data.

My console:

websocket.min.js:35 Uncaught TypeError: Cannot read property 'data' of
  undefined
      at receiveMessage (websocket.min.js:35)

message from cart to server: 10 // the number is correct

websocket.min.js:83 WebSocket is already in CLOSING or CLOSED state.

My websocket.js:

document.addEventListener('DOMContentLoaded', function(){
  'use strict';

  var ws_protocol = 'ws://';
  if (window.location.protocol == "https:")
    ws_protocol = 'wss://';
  var ws_url = ws_protocol + window.location.host + '/ws/auctions/' + qs;
  var webSocket = new WebSocket(ws_url);

  var amountbutton = document.getElementsByClassName('amountButton');
  var message_cart;

  webSocket.onopen = sendMessage();
  webSocket.onmessage = receiveMessage();

  function receiveMessage(e) {
    var msgData = JSON.parse(e.data);
    if ('auction_data' in msgData) {
        console.log("here we are, 'auction_data' in msgData");
    } else if ('cart_data' in msgData) {
        console.log("here we are, 'cart_data' in msgData");
    }
  };

  function sendMessage() {

    for(let i = 0; i < amountbutton.length; i++) {

      amountbutton[i].onclick = (e) => {
        if(!amountbutton[i].nextElementSibling) {
          message_cart = amountbutton[i].previousElementSibling.value;
          message_cart++;
        } else {
          message_cart = amountbutton[i].nextElementSibling.value;
          message_cart--;
        }
        console.log("message from cart to server: " + message_cart);
        webSocket.send(message_cart);
      }
    }
  }

  webSocket.onclose = function(e) {
    console.error('Websocket closed.');
  };

}, false);

Body:
In order for web socket to call your onopen and onmessage callbacks, you must assign them to listeners as a function, not as values these function are returning. So the solution is to just assign these functions without calling them, like that:

  webSocket.onopen = sendMessage; // <- no curly braces in there
  webSocket.onmessage = receiveMessage; // <- no curly braces in there

Hope it helps :)


问:
Calling external .js from ASP.NET MVC
I'm JavaScript newbie. What I'd like to be able to do is to call a function from .js file sitting in ASP.NET MVC project's scripts folder.

The function is:

```<code>function myfunction() {
    alert("HELLO");
}
</code>```

...and it resides in file brfix.js

On a viewpage I call it like this:

```<code><script src="../../Scripts/brfix.js" type="text/javascript"></script>

<script type="text/javascript">
    $(document).ready(function() {
        myfuntion();
    });
</script>
</code>```

But the code doesn't work. However, if I place js-code directly onto the viewpage, it works, like this:

```<code><script type="text/javascript">
    $(document).ready(function() {
        alert("HELLO");
    });
</script>
</code>```

How to call a file-based js function? Could some JavaScript-Big-Kahuna help me out? =)

答: If your mvc site is the root site in iis you can start the script src with a slash to get to the scripts. otherwise you can use an asp:ScriptManager to include the scripts</p>

OwnerDisplayName: Pompair

ContentLicense: CC BY-SA 3.0

Title: Calling external .js from ASP.NET MVC

Body:
I'm JavaScript newbie. What I'd like to be able to do is to call a function from .js file sitting in ASP.NET MVC project's scripts folder.

The function is:

function myfunction() {
    alert("HELLO");
}

...and it resides in file brfix.js

On a viewpage I call it like this:

But the code doesn't work. However, if I place js-code directly onto the viewpage, it works, like this:

How to call a file-based js function? Could some JavaScript-Big-Kahuna help me out? =)

OwnerDisplayName: AndreasKnudsen

ContentLicense: CC BY-SA 2.5


问:
Speeding up the implementation of the similarity of compounds' canonical smiles using rdkit
This wannabe bioinformatician needs your help. The code below finds the similarity of compounds' canonical smiles, using rdkit. After some research I understand it must be O(n)! (or not?) because for a small file of 944 entries it took 20 minutes while for the largest one which is 330.000 entries has been running for over 30 hours. Now, I now that one of its problems is that it doesn't compare the elements only once so that is one factor which slows it down. I read here that you can use the itertools library to make a comparison fast, but generally how could this code be made better? Any help would be appreciated while I try to learn :)</p>

```<code>from rdkit import Chem
from rdkit import DataStructs
from rdkit.Chem import AllChem
import pandas as pd

l =[]
s1 = []
s2 = []
d1 = []
d2 = []
with open('input_file.csv', 'r') as f:
    df = pd.read_csv(f, delimiter = ',', lineterminator = '\n', header = 0)
    for i in range(0, df.shape[0]):
        l.append(df.iloc[i, 1])

for i in range(0, df.shape[0]):
    for j in range(0, df.shape[0]):
        m1 = Chem.MolFromSmiles(df.iloc[i, 1])
        fp1 = AllChem.GetMorganFingerprint(m1,2)
        m2 = Chem.MolFromSmiles(df.iloc[j, 1])
        fp2 = AllChem.GetMorganFingerprint(m2,2)
        sim = DataStructs.DiceSimilarity(fp1,fp2)
        if sim >= 0.99:
            s1.append(i)
            s2.append(j)
for k in range(0, len(s1)):
    if df.iloc[s1[k], 0] != df.iloc[s2[k], 0]:
        d1.append(df.iloc[s1[k], 0])
        d2.append(df.iloc[s2[k], 0])
if len(d1) != 0:
    with open('outputfile.tsv', 'a') as f2:
        for o in range(0, len(d1)):
            f2.write(str(d1[o]) + '\t' + str(d2[0]) + '\n')
</code>```

答:
I have no idea what the algorithm is supposed to do, therefore I am not going to comment on it. But, you are stating that:

After some research I understand it must be O(n)!

What does the n represent? If the algorithm's time complexity is linear with respect to the number of rows in your dataset then your implementation must be incorrect. You have two nested loops in your code, both with the length of n which means that your algorithm is in O(n^2) at best (not considering what the other functions inside of the loop are doing).

Here are some suggestions how to speed up the code to a certain degree (in general when working with pandas).

You should avoid doing iterations on your own and you should avoid turning pandas data structures into python lists. Here is an example:

for i in range(0, df.shape[0]):
        l.append(df.iloc[i, 1])
```

<p>If you really need to store this in another variable then you can use </p>

<pre class="lang-py prettyprint-override"><code>l = df.iloc[:, 1].copy()
</code>```

This will be faster and it will not turn that series into a list (but I don't see l being used anywhere in your code so you should probably drop it entirely).

Another example is when you are computing those functions inside of the nested loop (again, I don't know what they are doing but it doesn't really matter).

for i ...
    for j ...
        m1 = Chem.MolFromSmiles(df.iloc[i, 1])
        fp1 = AllChem.GetMorganFingerprint(m1,2)
        m2 = Chem.MolFromSmiles(df.iloc[j, 1])
        fp2 = AllChem.GetMorganFingerprint(m2,2)
```

<p>First, you are computing the same values twice which can be time consuming and you are doing it within your custom loop which is not the best idea either.</p>

<p>Instead of those 4 lines (6 including the loop statements), you can create a new column of <code>fp</code> values:</p>

<pre class="lang-py prettyprint-override"><code>df["fp"] = df.iloc[:, i].copy()
df["fp"].apply(lambda x: AllChem.GetMorganFingerprint(Chem.MolFromSmiles(x), 2))
</code>```

This way, you don't have to compute the values twice and you don't have to write your own loop (at least for this part).

At this point, you will need to figure out how the mentioned O(n) algorithm works but I guess that it can be translated into pure vector operations which is probably going to be the most efficient implementation.

Body:
This wannabe bioinformatician needs your help. The code below finds the similarity of compounds' canonical smiles, using rdkit. After some research I understand it must be O(n)! (or not?) because for a small file of 944 entries it took 20 minutes while for the largest one which is 330.000 entries has been running for over 30 hours. Now, I now that one of its problems is that it doesn't compare the elements only once so that is one factor which slows it down. I read here that you can use the itertools library to make a comparison fast, but generally how could this code be made better? Any help would be appreciated while I try to learn :)

from rdkit import Chem
from rdkit import DataStructs
from rdkit.Chem import AllChem
import pandas as pd

l =[]
s1 = []
s2 = []
d1 = []
d2 = []
with open('input_file.csv', 'r') as f:
    df = pd.read_csv(f, delimiter = ',', lineterminator = '\n', header = 0)
    for i in range(0, df.shape[0]):
        l.append(df.iloc[i, 1])

for i in range(0, df.shape[0]):
    for j in range(0, df.shape[0]):
        m1 = Chem.MolFromSmiles(df.iloc[i, 1])
        fp1 = AllChem.GetMorganFingerprint(m1,2)
        m2 = Chem.MolFromSmiles(df.iloc[j, 1])
        fp2 = AllChem.GetMorganFingerprint(m2,2)
        sim = DataStructs.DiceSimilarity(fp1,fp2)
        if sim >= 0.99:
            s1.append(i)
            s2.append(j)
for k in range(0, len(s1)):
    if df.iloc[s1[k], 0] != df.iloc[s2[k], 0]:
        d1.append(df.iloc[s1[k], 0])
        d2.append(df.iloc[s2[k], 0])
if len(d1) != 0:
    with open('outputfile.tsv', 'a') as f2:
        for o in range(0, len(d1)):
            f2.write(str(d1[o]) + '\t' + str(d2[0]) + '\n')

Body:
I have no idea what the algorithm is supposed to do, therefore I am not going to comment on it. But, you are stating that:

After some research I understand it must be O(n)!

What does the n represent? If the algorithm's time complexity is linear with respect to the number of rows in your dataset then your implementation must be incorrect. You have two nested loops in your code, both with the length of n which means that your algorithm is in O(n^2) at best (not considering what the other functions inside of the loop are doing).

Here are some suggestions how to speed up the code to a certain degree (in general when working with pandas).

You should avoid doing iterations on your own and you should avoid turning pandas data structures into python lists. Here is an example:

for i in range(0, df.shape[0]):
        l.append(df.iloc[i, 1])

If you really need to store this in another variable then you can use

l = df.iloc[:, 1].copy()

This will be faster and it will not turn that series into a list (but I don't see l being used anywhere in your code so you should probably drop it entirely).

Another example is when you are computing those functions inside of the nested loop (again, I don't know what they are doing but it doesn't really matter).

for i ...
    for j ...
        m1 = Chem.MolFromSmiles(df.iloc[i, 1])
        fp1 = AllChem.GetMorganFingerprint(m1,2)
        m2 = Chem.MolFromSmiles(df.iloc[j, 1])
        fp2 = AllChem.GetMorganFingerprint(m2,2)

First, you are computing the same values twice which can be time consuming and you are doing it within your custom loop which is not the best idea either.

Instead of those 4 lines (6 including the loop statements), you can create a new column of fp values:

df["fp"] = df.iloc[:, i].copy()
df["fp"].apply(lambda x: AllChem.GetMorganFingerprint(Chem.MolFromSmiles(x), 2))

This way, you don't have to compute the values twice and you don't have to write your own loop (at least for this part).

At this point, you will need to figure out how the mentioned O(n) algorithm works but I guess that it can be translated into pure vector operations which is probably going to be the most efficient implementation.


问:
python regex separate assignment statements end with semicolon
I have a string composed of many assignment statements like below. I want to seperate them apart. So I came up with regex re.findall(r's\d+\.([^=]+)=([^;]+);', string)

```<code>s9.allowUpload=null;s9.analyse=null;s9.description=null;s9.fillblankType=null;s9.gmtCreate=1551272584901;s9.gmtModified=1577668049380;
</code>```

It works like

```<code>[('allowUpload', 'null'), ('analyse', 'null'), ('description', 'null'), ('fillblankType', 'null'), ('gmtCreate', '1551272584901'), ('gmtModified', '1577668049380')]
</code>```

Everything goes fine until I meet a value which also contains semicolon like s9.optionsDetail below.

```<code>s9.type=-1;s9.optionDtos=s42;s9.optionsDetail="[{\"content\":\"<p><span style=\\\"font-size:16px;font-family: \'Calibri\',sans-serif;\\\"  >j*m+i</span></p>\"}]";
</code>```

答:
@The fourth bird's answer uses the regularity of optionsDetail value, it doesn't rootly solve the semicolon occurence in string. Below is an example:

```<code>s133.plainTextTitle="\u4E49int a[5][5]; \u540E\uFF0C\u662F_________";
</code>```

```<code>s133.allowUpload=null;s133.analyse=null;s133.description=null;s133.fillblankType=null;s133.gmtCreate=1551272584908;s133.gmtModified=1577668049389;s133.id=1217514489;s133.judgeDtos=null;s133.judgerules="null";s133.ojCases=null;s133.ojMemLimit=null;s133.ojNeedInput=true;s133.ojSupportedLanguage=null;s133.ojSupportedLanguageList=null;s133.ojTimeLimit=null;s133.ojTryTime=null;s133.optionDtos=s174;s133.options=null;s133.optionsDetail="[{\"id\":7679941034291,\"content\":\"<p><span style=\\\"font-size: 16px; font-family: \'Times New Roman\', serif;\\\"  >a[1][0]</span></p>\",\"answer\":true,\"analyse\":null},{\"id\":17679941034291,\"content\":\"<p><span style=\\\"font-size:16px;font-family: \'Times New Roman\',\'serif\';\\\"  >a[0][1]</span></p>\",\"answer\":false,\"analyse\":null},{\"id\":27679941034291,\"content\":\"<p><span style=\\\"font-size:16px;font-family: \'Times New Roman\',\'serif\';\\\"  >a[1][1]</span></p>\",\"answer\":false,\"analyse\":null},{\"id\":37679941034291,\"content\":\"<p><span style=\\\"font-size:16px;font-family: \'Times New Roman\',\'serif\';\\\"  >a[1][5] </span></p>\",\"answer\":false,\"analyse\":null}]";s133.plainTextTitle="\u5728\u5B9A\u4E49int a[5][5]; \u540E\uFF0C\u6570\u7EC4a\u4E2D\u7684\u7B2C6\u4E2A\u5143\u7D20\u662F_________";s133.position=2;s133.sampleAnswerJson="null";s133.sampleAnswers=null;s133.score=2.00;s133.stdAnswer=null;s133.testId=1220061796;s133.title="<p><span style=\"font-size:16px;font-family:\u5B8B\u4F53;\"  >\u5728\u5B9A\u4E49</span><span style=\"font-size:16px;font-family:\'Times New Roman\',\'serif\';\"  >int a[5][5];  </span><span style=\"font-size:16px;font-family:\u5B8B\u4F53;\"  >\u540E\uFF0C\u6570\u7EC4</span><span style=\"font-size:16px;font-family:\'Times New Roman\',\'serif\';\"  >a</span><span style=\"font-size:16px;font-family:\u5B8B\u4F53;\"  >\u4E2D\u7684\u7B2C</span><span style=\"font-size:16px;font-family:\'Times New Roman\',\'serif\';\"  >6</span><span style=\"font-size:16px;font-family:\u5B8B\u4F53;\"  >\u4E2A\u5143\u7D20\u662F</span><span style=\"font-size: 16px;font-family:\'Times New Roman\',\'serif\';\"  >_________</span></p>";s133.titleAttachment="null";s133.titleAttachmentDtos=null;s133.type=1;
</code>```

I came up with the idea to split the string using s133. which can be got with regex (s\d+\.). Then I will get a list like

```<code>['', 'allowUpload=null;', 'analyse=null;']
</code>```

After discarding the first element and the ; at the end of each element, using split("=", 1) to split on the first occurence of = works just fine.

This method has an obvious shortcoming, it will get false result when s133. appears like s133.plainTextTitle="s133.plainTextTitle". But I think this rarely happends.

Body:
I have a string composed of many assignment statements like below. I want to seperate them apart. So I came up with regex re.findall(r's\d+\.([^=]+)=([^;]+);', string)

s9.allowUpload=null;s9.analyse=null;s9.description=null;s9.fillblankType=null;s9.gmtCreate=1551272584901;s9.gmtModified=1577668049380;

It works like

[('allowUpload', 'null'), ('analyse', 'null'), ('description', 'null'), ('fillblankType', 'null'), ('gmtCreate', '1551272584901'), ('gmtModified', '1577668049380')]

Everything goes fine until I meet a value which also contains semicolon like s9.optionsDetail below.

s9.type=-1;s9.optionDtos=s42;s9.optionsDetail="[{\"content\":\"
j*m+i
\"}]";

Body:
@The fourth bird's answer uses the regularity of optionsDetail value, it doesn't rootly solve the semicolon occurence in string. Below is an example:

s133.plainTextTitle="\u4E49int a[5][5]; \u540E\uFF0C\u662F_________";

s133.allowUpload=null;s133.analyse=null;s133.description=null;s133.fillblankType=null;s133.gmtCreate=1551272584908;s133.gmtModified=1577668049389;s133.id=1217514489;s133.judgeDtos=null;s133.judgerules="null";s133.ojCases=null;s133.ojMemLimit=null;s133.ojNeedInput=true;s133.ojSupportedLanguage=null;s133.ojSupportedLanguageList=null;s133.ojTimeLimit=null;s133.ojTryTime=null;s133.optionDtos=s174;s133.options=null;s133.optionsDetail="[{\"id\":7679941034291,\"content\":\"<p><span style=\\\"font-size: 16px; font-family: \'Times New Roman\', serif;\\\"  >a[1][0]</span></p>\",\"answer\":true,\"analyse\":null},{\"id\":17679941034291,\"content\":\"<p><span style=\\\"font-size:16px;font-family: \'Times New Roman\',\'serif\';\\\"  >a[0][1]</span></p>\",\"answer\":false,\"analyse\":null},{\"id\":27679941034291,\"content\":\"<p><span style=\\\"font-size:16px;font-family: \'Times New Roman\',\'serif\';\\\"  >a[1][1]</span></p>\",\"answer\":false,\"analyse\":null},{\"id\":37679941034291,\"content\":\"<p><span style=\\\"font-size:16px;font-family: \'Times New Roman\',\'serif\';\\\"  >a[1][5]&nbsp;</span></p>\",\"answer\":false,\"analyse\":null}]";s133.plainTextTitle="\u5728\u5B9A\u4E49int a[5][5]; \u540E\uFF0C\u6570\u7EC4a\u4E2D\u7684\u7B2C6\u4E2A\u5143\u7D20\u662F_________";s133.position=2;s133.sampleAnswerJson="null";s133.sampleAnswers=null;s133.score=2.00;s133.stdAnswer=null;s133.testId=1220061796;s133.title="<p><span style=\"font-size:16px;font-family:\u5B8B\u4F53;\"  >\u5728\u5B9A\u4E49</span><span style=\"font-size:16px;font-family:\'Times New Roman\',\'serif\';\"  >int a[5][5];&nbsp; </span><span style=\"font-size:16px;font-family:\u5B8B\u4F53;\"  >\u540E\uFF0C\u6570\u7EC4</span><span style=\"font-size:16px;font-family:\'Times New Roman\',\'serif\';\"  >a</span><span style=\"font-size:16px;font-family:\u5B8B\u4F53;\"  >\u4E2D\u7684\u7B2C</span><span style=\"font-size:16px;font-family:\'Times New Roman\',\'serif\';\"  >6</span><span style=\"font-size:16px;font-family:\u5B8B\u4F53;\"  >\u4E2A\u5143\u7D20\u662F</span><span style=\"font-size: 16px;font-family:\'Times New Roman\',\'serif\';\"  >_________</span></p>";s133.titleAttachment="null";s133.titleAttachmentDtos=null;s133.type=1;

I came up with the idea to split the string using s133. which can be got with regex (s\d+\.). Then I will get a list like

['', 'allowUpload=null;', 'analyse=null;']

After discarding the first element and the ; at the end of each element, using split("=", 1) to split on the first occurence of = works just fine.

This method has an obvious shortcoming, it will get false result when s133. appears like s133.plainTextTitle="s133.plainTextTitle". But I think this rarely happends.


问:
Access JS object with a key
I can access a value like driver.my_friends["793659690"].name but now I am using it in a loop where key will hold the key.

driver.my_friends[key].name doesn't work. Says undefined, and driver.my_friends["key"].name will look for a key named key. So how do I use it so that the variable of the variable is evaluated too.

答:
driver.my_friends[key].name is the right way. It is possible that no key like key exists in driver.my_friends =) and/or that .name doesn't exist in that object.

You can debug that very easily:

```<code>console.log(driver.my_friends[key]);
console.log(driver.my_friends[key].name);
</code>```

Even IE8 has a console like that.

Title: Access JS object with a key

Body:
driver.my_friends[key].name is the right way. It is possible that no key like key exists in driver.my_friends =) and/or that .name doesn't exist in that object.

You can debug that very easily:

console.log(driver.my_friends[key]);
console.log(driver.my_friends[key].name);

Even IE8 has a console like that.


问:
Linux expect script sometimes ending with `Connection closed by foreign host`, is this expect script or device issue?
I am running CentOS 7.6

```<code>$ cat /etc/system-release
CentOS Linux release 7.6.1810 (Core)
</code>```

This is the most recent version of expect from the repos.

```<code>$ expect -version
expect version 5.45
</code>```

As per your suggestion, I have adjusted my code to make this easier to fix, the authentication part should not be a problem so I removed it for now, below is my expect code, testing a device that does not have authentication.

```<code>$ cat runCommands.exp
spawn telnet 10.220.64.67
set prompt "#"
expect ">"
send "enable\r"
expect $prompt
send "terminal length 200\r"
expect $prompt
send "terminal more off\r"
expect $prompt
send "show hw-inventory details\r"
expect $prompt
send "exit\r"
expect eof
</code>```

This is how I am running my expect script, it starts correctly but at the end it just stops.

```<code>$ expect -f ./runCommands.exp
spawn telnet 10.220.64.67
Trying 10.220.64.67...
Connected to 10.220.64.67.
Escape character is '^]'.

******************************************************************
*                                                                *
*                  Tellabs 8609 Network Element                  *
*                                                                *
*     Copyright (c) 2004-2015 Tellabs. All rights reserved.      *
*                                                                *
******************************************************************
Enter configuration commands, one per line. End with ^Z
HENKEL_CAPITAL_2-EQU>enable
HENKEL_CAPITAL_2-EQU#terminal length 200
HENKEL_CAPITAL_2-EQU#terminal more off
HENKEL_CAPITAL_2-EQU#show hw-inventory details
This is node 1643 of type 8609 and subrack address 0.
    unit in slot 1 is part of inventory and UP AND RUNNING
        unit 1 of width 1 has serial number 40601444713, CLEI code IPMVU00DRB
        top level serial number 40601445792
        manufacturing date 2016-3-30, 4:42:19.0, +0:00
        part# 82.86S-8609-R6 rev C
        HW type sbb2284-8609(2284) v3.0.1 SW type 0 v2.0.331
            Pmax=70.0W, Ptyp=60.0W
        infomodel FP2.0 (2.2.0); internal SW v.2.0.331
            Supported infomodels:
                FP2.0 (2.2.0)
        CPLD active revision: 0x0130
        WPIF expected and active revision: 0x001a
        LMIF expected and active revision: 0x0023
        TOCK expected and active revision: 0x0416
        module IF0 (LEFT) of type 4*100/1000BASE-X(9094)
            SFP connector 0 data:
                [0] type of serial transceiver: 3 (SFP transceiver)
                [1] extended identifier of type of serial transceiver: 4
                [2] connector type: 7(LC)
                [3] infiniband compliance code: 0
                [4] sonet compliance code4: 0
                [5] sonet compliance code5: 0
                [6] gigabit ethernet compliance code: 2, 1000BASE-LX
                [11] serial encoding type: 1 8B10B
                [14] link length for 9/125mm fiber (km): 52
                [15] link length for 9/125mm fiber (100m): 255
                [16] link length for 50/125mm fiber (10m): 0
                [17] link length for 62.5/125mm fiber (10m): 0
                [18] link length for copper (m): 0
                [20] vendor name: FINISAR CORP.
                [37] vendor organizationally unique: 36965
                [40] vendor part number: FTLF1419P1BCL-TL
                [56] vendor revision number: A
                [60] Laser wavelength: 1310 nm
                [62] reserved field: 0
                [68] vendor serial number: PU117T5
                [84] vendor's date (yy-mm-dd): 15-07-03
                [90] vendor's date (vendor specific part):
                [224-241] Tellabs part number: 81.86T-S001-13S-R6
                [242-243] Tellabs revision:  A
                [244-253] Tellabs CLEI code:  IPU3AVSKAA
                [255] Tellabs checksum: 0x3C
                [d102] Tx power: 2.6 dBm (1.8 mW)
                [d104] Rx power: -7.8 dBm (0.17 mW)
            SFP connector 1 is not present
            SFP connector 2 is not present
            SFP connector 3 is not present
        module IF1 (MIDDLE LEFT) of type 4*100/1000BASE-X(9094)
            SFP connector 0 data:
                [0] type of serial transceiver: 3 (SFP transceiver)
                [1] extended identifier of type of serial transceiver: 4
                [2] connector type: 7(LC)
                [3] infiniband compliance code: 0
                [4] sonet compliance code4: 0
                [5] sonet compliance code5: 0
                [6] gigabit ethernet compliance code: 2, 1000BASE-LX
                [11] serial encoding type: 1 8B10B
                [14] link length for 9/125mm fiber (km): 40
                [15] link length for 9/125mm fiber (100m): 0
                [16] link length for 50/125mm fiber (10m): 0
                [17] link length for 62.5/125mm fiber (10m): 0
                [18] link length for copper (m): 0
                [20] vendor name: HG GENUINE
                [37] vendor organizationally Connection closed by foreign host.
</code>```

As you can see above, the error I am getting is Connection closed by foreign host and I can not get the full output of the show hw-inventory details command, not sure if the size of the output could be affecting this.

As the only resource I know for debugging this expect script is adding the -d flag I have run exactly the same script with that option in case we can get an idea about what is going on here.

```<code>$ expect -df ./runCommands.exp
expect version 5.45
argv[0] = expect  argv[1] = -df  argv[2] = ./runCommands.exp
set argc 0
set argv0 "./runCommands.exp"
set argv ""
executing commands from command file ./runCommands.exp
spawn telnet 10.220.64.67
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {15767}

expect: does "" (spawn_id exp6) match glob pattern ">"? no
Trying 10.220.64.67...

expect: does "Trying 10.220.64.67...\r\r\n" (spawn_id exp6) match glob pattern ">"? no
Connected to 10.220.64.67.
Escape character is '^]'.

expect: does "Trying 10.220.64.67...\r\r\nConnected to 10.220.64.67.\r\r\nEscape character is '^]'.\r\r\n" (spawn_id exp6) match glob pattern ">"? no

******************************************************************
*                                                                *
*                  Tellabs 8609 Network Element                  *
*                                                                *
*     Copyright (c) 2004-2015 Tellabs. All rights reserved.      *
*                                                                *
******************************************************************
Enter configuration commands, one per line. End with ^Z
HENKEL_CAPITAL_2-EQU>
expect: does "Trying 10.220.64.67...\r\r\nConnected to 10.220.64.67.\r\r\nEscape character is '^]'.\r\r\n\r\r\n******************************************************************\r\r\n*                                                                *\r\r\n*                  Tellabs 8609 Network Element                  *\r\r\n*                                                                *\r\r\n*     Copyright (c) 2004-2015 Tellabs. All rights reserved.      *\r\r\n*                                                                *\r\r\n******************************************************************\r\r\nEnter configuration commands, one per line. End with ^Z\r\nHENKEL_CAPITAL_2-EQU>" (spawn_id exp6) match glob pattern ">"? yes
expect: set expect_out(0,string) ">"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "Trying 10.220.64.67...\r\r\nConnected to 10.220.64.67.\r\r\nEscape character is '^]'.\r\r\n\r\r\n******************************************************************\r\r\n*                                                                *\r\r\n*                  Tellabs 8609 Network Element                  *\r\r\n*                                                                *\r\r\n*     Copyright (c) 2004-2015 Tellabs. All rights reserved.      *\r\r\n*                                                                *\r\r\n******************************************************************\r\r\nEnter configuration commands, one per line. End with ^Z\r\nHENKEL_CAPITAL_2-EQU>"
send: sending "enable\r" to { exp6 }

expect: does "" (spawn_id exp6) match glob pattern "#"? no
HENKEL_CAPITAL_2-EQU>
expect: does "\r                     \u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008HENKEL_CAPITAL_2-EQU>" (spawn_id exp6) match glob pattern "#"? no
enable

expect: does "\r                     \u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008HENKEL_CAPITAL_2-EQU>enable\r\n" (spawn_id exp6) match glob pattern "#"? no
HENKEL_CAPITAL_2-EQU#
expect: does "\r                     \u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008HENKEL_CAPITAL_2-EQU>enable\r\nHENKEL_CAPITAL_2-EQU#" (spawn_id exp6) match glob pattern "#"? yes
expect: set expect_out(0,string) "#"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "\r                     \u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008HENKEL_CAPITAL_2-EQU>enable\r\nHENKEL_CAPITAL_2-EQU#"
send: sending "terminal length 200\r" to { exp6 }

expect: does "" (spawn_id exp6) match glob pattern "#"? no
terminal length 200

expect: does "terminal length 200\r\n" (spawn_id exp6) match glob pattern "#"? no
HENKEL_CAPITAL_2-EQU#
expect: does "terminal length 200\r\nHENKEL_CAPITAL_2-EQU#" (spawn_id exp6) match glob pattern "#"? yes
expect: set expect_out(0,string) "#"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "terminal length 200\r\nHENKEL_CAPITAL_2-EQU#"
send: sending "terminal more off\r" to { exp6 }

expect: does "" (spawn_id exp6) match glob pattern "#"? no
terminal more off

expect: does "terminal more off\r\n" (spawn_id exp6) match glob pattern "#"? no
HENKEL_CAPITAL_2-EQU#
expect: does "terminal more off\r\nHENKEL_CAPITAL_2-EQU#" (spawn_id exp6) match glob pattern "#"? yes
expect: set expect_out(0,string) "#"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "terminal more off\r\nHENKEL_CAPITAL_2-EQU#"
send: sending "show hw-inventory details\r" to { exp6 }

expect: does "" (spawn_id exp6) match glob pattern "#"? no
show hw-inventory details

expect: does "show hw-inventory details\r\n" (spawn_id exp6) match glob pattern "#"? no
This is node 1643 of type 8609 and subrack address 0.
    unit in slot 1 is pa
expect: does "show hw-inventory details\r\nThis is node 1643 of type 8609 and subrack address 0.\r\n    unit in slot 1 is pa" (spawn_id exp6) match glob pattern "#"? no
r
expect: does "show hw-inventory details\r\nThis is node 1643 of type 8609 and subrack address 0.\r\n    unit in slot 1 is par" (spawn_id exp6) match glob pattern "#"? no
t of inventory and UP AND RUNNING
        unit 1 of width 1 has serial number 4
expect: does "show hw-inventory details\r\nThis is node 1643 of type 8609 and subrack address 0.\r\n    unit in slot 1 is part of inventory and UP AND RUNNING\r\n        unit 1 of width 1 has serial number 4" (spawn_id exp6) match glob pattern "#"? no
0601444713, CLEI code IPMVU00DRB
        top level serial number 40601445792
        manufacturing date 2016-3-30, 4:42:19.0, +0:00
        part# 82.86S-8609
expect: does "show hw-inventory details\r\nThis is node 1643 of type 8609 and subrack address 0.\r\n    unit in slot 1 is part of inventory and UP AND RUNNING\r\n        unit 1 of width 1 has serial number 40601444713, CLEI code IPMVU00DRB\r\n        top level serial number 40601445792\r\n        manufacturing date 2016-3-30, 4:42:19.0, +0:00\r\n        part# 82.86S-8609" (spawn_id exp6) match glob pattern "#"? yes
expect: set expect_out(0,string) "#"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "show hw-inventory details\r\nThis is node 1643 of type 8609 and subrack address 0.\r\n    unit in slot 1 is part of inventory and UP AND RUNNING\r\n        unit 1 of width 1 has serial number 40601444713, CLEI code IPMVU00DRB\r\n        top level serial number 40601445792\r\n        manufacturing date 2016-3-30, 4:42:19.0, +0:00\r\n        part#"
send: sending "exit\r" to { exp6 }
-R6 rev C
        HW type sbb2284-8609(2284) v3.0.1 SW type 0 v2.0.331
            Pmax=70.0W, Ptyp=60.0W
        infomodel FP2.0 (2.2.0); internal SW v.2.0.331
            Supported infomodels:
                FP2.0 (2.2.0)
        CPLD active revision: 0x0130
        WPIF expected and active revision: 0x001a
        LMIF expected and active revision: 0x0023
        TOCK expected and active revision: 0x0416
        module IF0 (LEFT) of type 4*100/1000BASE-X(9094)
            SFP connector 0 data:
                [0] type of serial transceiver: 3 (SFP transceiver)
                [1] extended identifier of type of serial transceiver: 4
                [2] connector type: 7(LC)
                [3] infiniband compliance code: 0
                [4] sonet compliance code4: 0
                [5] sonet compliance code5: 0
                [6] gigabit ethernet compliance code: 2, 1000BASE-LX
                [11] serial encoding type: 1 8B10B
                [14] link length for 9/125mm fiber (km): 52
                [15] link length for 9/125mm fiber (100m): 255
                [16] link length for 50/125mm fiber (10m): 0
                [17] link length for 62.5/125mm fiber (10m): 0
                [18] link length for copper (m): 0
                [20] vendor name: FINISAR CORP.
                [37] vendor organizationally unique: 36965
                [40] vendor part number: FTLF1419P1BCL-TL
                [56] vendor revision number: A
                [60] Laser wavelength: 1310 nm
                [62] reserved field: 0
                [68] vendor serial number: PU117T5
                [84] vendor's date (yy-mm-dd): 15-07-03
                [90] vendor's date (vendor specific part):
                [224-241] Tellabs part number: 81.86T-S001-13S-R6
                [242-243] Tellabs revision:  A
                [244-253] Tellabs CLEI code:  IPU3AVSKAA
                [255] Tellabs checksum: 0x3C
                [d102] Tx power: 2.6 dBm (1.8 mW)
                [d104] Rx power: -7.7 dBm (0.17 mW)
            SFP connector 1 is not present
            SFP connector 2 is not present
            SFP connector 3 is not present
        module IF1 (MIDDLE LEFT) of type 4*100/1000BASE-X(9094)
            SFP connector 0 data:
                [0] type of serial transceiver: 3 (SFP transceiver)
                [1] extended identifier of type of serial transceiver: 4
                [2] connector type: 7(LC)
                [3] infiniband compliance code: 0
                [4] sonet compliance code4: 0
                [5] sonet compliance code5: 0
                [6] gigabit ethernet compliance code: 2, 1000BASE-LX
                [11] serial encoding type: 1 8B10B
                [14] link length for 9/125mm fiber (km): 40
                [15] link length for 9/125mm fiber (100m): 0
                [16] link length for 50/125mm fiber (10m): 0
                [17] link length for 62.5/125mm fiber (10m): 0
                [18] link length for copper (m): 0
                [20] vendor name: HG GENUINE
                [37] vendor organizationally unique: 0
                [40] vendor part number: MXPD-243MD
                [56] vendor revision number:
                [60] Laser wavelength: 1310 nm
                [62] reserved field: 0
                [68] vendor serial number: ME12112000011
                [84] vendor's date (yy-mm-dd): 12-03-17
                [90] vendor's date (vendor specific part):
                [224-255] vendor specific ID field : 0x00000000
                    0x00000000 0x00000000 0x00000000 0x00000000
                    0x00000000 0x00000000 0x00000000
                [d102] Tx power: -3.0 dBm (0.50 mW)
                [d104] Rx power: -13 dBm (50 uW)
            SFP connector 1 is not present
            SFP connector 2 is Connection closed by foreign host.
expect: read eof
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) " 82.86S-8609-R6 rev C\r\n        HW type sbb2284-8609(2284) v3.0.1 SW type 0 v2.0.331\r\n            Pmax=70.0W, Ptyp=60.0W\r\n        infomodel FP2.0 (2.2.0); internal SW v.2.0.331\r\n            Supported infomodels:\r\n                FP2.0 (2.2.0)\r\n        CPLD active revision: 0x0130\r\n        WPIF expected and active revision: 0x001a\r\n        LMIF expected and active revision: 0x0023\r\n        TOCK expected and active revision: 0x0416\r\n        module IF0 (LEFT) of type 4*100/1000BASE-X(9094)\r\n            SFP connector 0 data:\r\n                [0] type of serial transceiver: 3 (SFP transceiver)\r\n                [1] extended identifier of type of serial transceiver: 4\r\n                [2] connector type: 7(LC)\r\n                [3] infiniband compliance code: 0\r\n                [4] sonet compliance code4: 0\r\n                [5] sonet compliance code5: 0\r\n                [6] gigabit ethernet compliance code: 2, 1000BASE-LX\r\n                [11] serial encoding type: 1 8B10B\r\n                [14] link length for 9/125mm fiber (km): 52\r\n                [15] link length for 9/125mm fiber (100m): 255\r\n                [16] link length for 50/125mm fiber (10m): 0\r\n                [17] link length for 62.5/125mm fiber (10m): 0\r\n                [18] link length for copper (m): 0\r\n                [20] vendor name: FINISAR CORP.   \r\n                [37] vendor organizationally unique: 36965\r\n                [40] vendor part number: FTLF1419P1BCL-TL\r\n                [56] vendor revision number: A   \r\n                [60] Laser wavelength: 1310 nm\r\n                [62] reserved field: 0\r\n                [68] vendor serial number: PU117T5         \r\n                [84] vendor's date (yy-mm-dd): 15-07-03\r\n                [90] vendor's date (vendor specific part):   \r\n                [224-241] Tellabs part number: 81.86T-S001-13S-R6\r\n                [242-243] Tellabs revision:  A \r\n                [244-253] Tellabs CLEI code:  IPU3AVSKAA\r\n                [255] Tellabs checksum: 0x3C\r\n                [d102] Tx power: 2.6 dBm (1.8 mW)\r\n                [d104] Rx power: -7.7 dBm (0.17 mW)\r\n            SFP connector 1 is not present\r\n            SFP connector 2 is not present\r\n            SFP connector 3 is not present\r\n        module IF1 (MIDDLE LEFT) of type 4*100/1000BASE-X(9094)\r\n            SFP connector 0 data:\r\n                [0] type of serial transceiver: 3 (SFP transceiver)\r\n                [1] extended identifier of type of serial transceiver: 4\r\n                [2] connector type: 7(LC)\r\n                [3] infiniband compliance code: 0\r\n                [4] sonet compliance code4: 0\r\n                [5] sonet compliance code5: 0\r\n                [6] gigabit ethernet compliance code: 2, 1000BASE-LX\r\n                [11] serial encoding type: 1 8B10B\r\n                [14] link length for 9/125mm fiber (km): 40\r\n                [15] link length for 9/125mm fiber (100m): 0\r\n                [16] link length for 50/125mm fiber (10m): 0\r\n                [17] link length for 62.5/125mm fiber (10m): 0\r\n                [18] link length for copper (m): 0\r\n                [20] vendor name: HG GENUINE      \r\n                [37] vendor organizationally unique: 0\r\n                [40] vendor part number: MXPD-243MD      \r\n                [56] vendor revision number: \r\n                [60] Laser wavelength: 1310 nm\r\n                [62] reserved field: 0\r\n                [68] vendor serial number: ME12112000011   \r\n                [84] vendor's date (yy-mm-dd): 12-03-17\r\n                [90] vendor's date (vendor specific part):   \r\n                [224-255] vendor specific ID field : 0x00000000 \r\n                    0x00000000 0x00000000 0x00000000 0x00000000 \r\n                    0x00000000 0x00000000 0x00000000 \r\n                [d102] Tx power: -3.0 dBm (0.50 mW)\r\n                [d104] Rx power: -13 dBm (50 uW)\r\n            SFP connector 1 is not present\r\n            SFP connector 2 is Connection closed by foreign host.\r\r\n"
</code>```

Do you think this could be an issue with the expect script itself or there could be something else related to the telnet device?

If you are willing to do so we can have a screen session and we can work together on this, at this point I feel desperate about this weird issue, not sure how to keep moving forward.

This is the full expected output:

```<code>$ telnet 10.220.64.67
Trying 10.220.64.67...
Connected to 10.220.64.67.
Escape character is '^]'.

******************************************************************
*                                                                *
*                  Tellabs 8609 Network Element                  *
*                                                                *
*     Copyright (c) 2004-2015 Tellabs. All rights reserved.      *
*                                                                *
******************************************************************
Enter configuration commands, one per line. End with ^Z
HENKEL_CAPITAL_2-EQU>enable
HENKEL_CAPITAL_2-EQU#show hw-inventory details
This is node 1643 of type 8609 and subrack address 0.
    unit in slot 1 is part of inventory and UP AND RUNNING
        unit 1 of width 1 has serial number 40601444713, CLEI code IPMVU00DRB
        top level serial number 40601445792
        manufacturing date 2016-3-30, 4:42:19.0, +0:00
        part# 82.86S-8609-R6 rev C
        HW type sbb2284-8609(2284) v3.0.1 SW type 0 v2.0.331
            Pmax=70.0W, Ptyp=60.0W
        infomodel FP2.0 (2.2.0); internal SW v.2.0.331
            Supported infomodels:
                FP2.0 (2.2.0)
        CPLD active revision: 0x0130
        WPIF expected and active revision: 0x001a
        LMIF expected and active revision: 0x0023
        TOCK expected and active revision: 0x0416
        module IF0 (LEFT) of type 4*100/1000BASE-X(9094)
            SFP connector 0 data:
                [0] type of serial transceiver: 3 (SFP transceiver)
                [1] extended identifier of type of serial transceiver: 4
                [2] connector type: 7(LC)
                [3] infiniband compliance code: 0
                [4] sonet compliance code4: 0
                [5] sonet compliance code5: 0
                [6] gigabit ethernet compliance code: 2, 1000BASE-LX
                [11] serial encoding type: 1 8B10B
                [14] link length for 9/125mm fiber (km): 52
                [15] link length for 9/125mm fiber (100m): 255
                [16] link length for 50/125mm fiber (10m): 0
                [17] link length for 62.5/125mm fiber (10m): 0
                [18] link length for copper (m): 0
                [20] vendor name: FINISAR CORP.
                [37] vendor organizationally unique: 36965
                [40] vendor part number: FTLF1419P1BCL-TL
                [56] vendor revision number: A
                [60] Laser wavelength: 1310 nm
                [62] reserved field: 0
                [68] vendor serial number: PU117T5
                [84] vendor's date (yy-mm-dd): 15-07-03
                [90] vendor's date (vendor specific part):
                [224-241] Tellabs part number: 81.86T-S001-13S-R6
                [242-243] Tellabs revision:  A
                [244-253] Tellabs CLEI code:  IPU3AVSKAA
                [255] Tellabs checksum: 0x3C
                [d102] Tx power: 2.6 dBm (1.8 mW)
                [d104] Rx power: -7.7 dBm (0.17 mW)
            SFP connector 1 is not present
            SFP connector 2 is not present
            SFP connector 3 is not present
        module IF1 (MIDDLE LEFT) of type 4*100/1000BASE-X(9094)
            SFP connector 0 data:
                [0] type of serial transceiver: 3 (SFP transceiver)
                [1] extended identifier of type of serial transceiver: 4
                [2] connector type: 7(LC)
                [3] infiniband compliance code: 0
                [4] sonet compliance code4: 0
                [5] sonet compliance code5: 0
                [6] gigabit ethernet compliance code: 2, 1000BASE-LX
                [11] serial encoding type: 1 8B10B
                [14] link length for 9/125mm fiber (km): 40
                [15] link length for 9/125mm fiber (100m): 0
                [16] link length for 50/125mm fiber (10m): 0
                [17] link length for 62.5/125mm fiber (10m): 0
                [18] link length for copper (m): 0
                [20] vendor name: HG GENUINE
                [37] vendor organizationally unique: 0
                [40] vendor part number: MXPD-243MD
                [56] vendor revision number:
                [60] Laser wavelength: 1310 nm
                [62] reserved field: 0
                [68] vendor serial number: ME12112000011
                [84] vendor's date (yy-mm-dd): 12-03-17
                [90] vendor's date (vendor specific part):
                [224-255] vendor specific ID field : 0x00000000
                    0x00000000 0x00000000 0x00000000 0x00000000
                    0x00000000 0x00000000 0x00000000
                [d102] Tx power: -3.0 dBm (0.50 mW)
                [d104] Rx power: -13 dBm (50 uW)
            SFP connector 1 is not present
            SFP connector 2 is not present
            SFP connector 3 is not present
        module IF2 (MIDDLE) of type 4*10/100/1000BASE-T(9093)
        module IF3 (RIGHT MIDDLE) of type 8*10/100BASE-TX-LM(2243) v2.0.1 (hot insert)
            serial number 40601373354, CLEI code IPU3A7TKAA
            top level serial number 40601376329
            manufacturing date 2015-10-20, 8:51:59.0, +0:00
            part# 81.86LFETX82243-R6 rev D
            Pmax=4.60W, Ptyp=4.00W
        module IF4 (RIGHT) of type 8*10/100BASE-TX-LM(2243) v2.0.1 (hot insert)
            serial number 40601405399, CLEI code IPU3A7TKAA
            top level serial number 40601405948
            manufacturing date 2015-12-31, 0:06:43.0, +0:00
            part# 81.86LFETX82243-R6 rev D
            Pmax=4.60W, Ptyp=4.00W
        module COOLING FAN 1 of type fmb2285-coolingFan(2285)
        module PRIMARY POWER of type -48Vdc(2264)(2264) v2.0.0
            serial number 40601425507, CLEI code IPUPAKMLAA
            top level serial number 40601430234
            manufacturing date 2016-2-26, 17:02:48.9, +8:00
            part# 81.86P-0911DC48-R6 rev C
            Pmax=0.00W, Ptyp=0.00W
        module OVEN CONTROLLED OSCILLATOR of type vid9096-ocxo(9096) v1.0.0
        interface module 0 has
            expected type 4*100/1000BASE-X
            active   type 4*100/1000BASE-X
            existing type 4*100/1000BASE-X
            mode is not relevant
        interface module 1 has
            expected type 4*100/1000BASE-X
            active   type 4*100/1000BASE-X
            existing type 4*100/1000BASE-X
            mode is not relevant
        interface module 2 has
            expected type 4*10/100/1000BASE-T
            active   type 4*10/100/1000BASE-T
            existing type 4*10/100/1000BASE-T
            mode is not relevant
        interface module 3 has
            expected type 8*10/100BASE-TX-LM
            active   type 8*10/100BASE-TX-LM
            existing type 8*10/100BASE-TX-LM
            mode is not relevant
            Pmax=4.60W, Ptyp=4.00W
        interface module 4 has
            expected type 8*10/100BASE-TX-LM
            active   type 8*10/100BASE-TX-LM
            existing type 8*10/100BASE-TX-LM
            mode is not relevant
            Pmax=4.60W, Ptyp=4.00W
        power module primary has
            expected type -48Vdc(2264)
            active   type -48Vdc(2264)
            existing type -48Vdc(2264)
            mode is not relevant
            Pmax=0.00W, Ptyp=0.00W
        oven controlled oscillator has
            expected type vid9096-ocxo
            active   type vid9096-ocxo
            existing type vid9096-ocxo
            mode is not relevant

HENKEL_CAPITAL_2-EQU#exit
Connection closed by foreign host.
</code>```

In the previous output, I entered the commands manually and it worked correctly the only difference is that I did not use the terminal more off and terminal length 200 commands.

```<code>$ telnet 10.220.64.67
Enter configuration commands, one per line. End with ^Z
HENKEL_CAPITAL_2-EQU>enable
HENKEL_CAPITAL_2-EQU#show hw-inventory details
**[short output... due to the limit of the stackoverflow text box]**
--More--
            mode is not relevant
HENKEL_CAPITAL_2-EQU#exit
Connection closed by foreign host.
</code>```

When I see the --More-- string I just type the space bar in order to get more output until the last prompt HENKEL_CAPITAL_2-EQU# is shown, then I just type the exit command.

答:
Your main problem seems to be that you are interleaving code (especially those sleep 1s!) at different levels, resulting in a script that's actually pure gibberish. That the code isn't crashing is pure happenstance.

Rewriting the section with the problems while taking a guess as to what you need...

```<code># Handle login
expect {
    "user name:" {
        send "$user\r"
        exp_continue; # keep waiting
    }
    "password:" {
        send "$password\r"
        exp_continue; # keep waiting
    }
    ">" {
        # Got a logged-in prompt so stop waiting (by not exp_continuing)
    }
}

# Handle what's going on remotely; note that we've a prompt at this point
# and can use simple challenge/response coding from here on
set prompt "# "
send "enable\r"
expect $prompt
send "terminal length 200\r"
expect $prompt
send "terminal more off\r"
foreach cmd $commands {
    expect $prompt
    send "$cmd\r"
}
expect $prompt
send "exit\r"
expect eof
</code>```

This technique becomes more valuable once you add in error handling rather than trusting everything to work, as one of the main powers of expect is being able to wait for several things at once. You don't usually need that, but it's super-valuable when you do!

You don't normally need to add in sleep calls, not when you're just sending a command an waiting for the prompt back.

Body:
I am running CentOS 7.6

$ cat /etc/system-release
CentOS Linux release 7.6.1810 (Core)

This is the most recent version of expect from the repos.

$ expect -version
expect version 5.45

As per your suggestion, I have adjusted my code to make this easier to fix, the authentication part should not be a problem so I removed it for now, below is my expect code, testing a device that does not have authentication.

$ cat runCommands.exp
spawn telnet 10.220.64.67
set prompt "#"
expect ">"
send "enable\r"
expect $prompt
send "terminal length 200\r"
expect $prompt
send "terminal more off\r"
expect $prompt
send "show hw-inventory details\r"
expect $prompt
send "exit\r"
expect eof

This is how I am running my expect script, it starts correctly but at the end it just stops.

$ expect -f ./runCommands.exp
spawn telnet 10.220.64.67
Trying 10.220.64.67...
Connected to 10.220.64.67.
Escape character is '^]'.

******************************************************************
*                                                                *
*                  Tellabs 8609 Network Element                  *
*                                                                *
*     Copyright (c) 2004-2015 Tellabs. All rights reserved.      *
*                                                                *
******************************************************************
Enter configuration commands, one per line. End with ^Z
HENKEL_CAPITAL_2-EQU>enable
HENKEL_CAPITAL_2-EQU#terminal length 200
HENKEL_CAPITAL_2-EQU#terminal more off
HENKEL_CAPITAL_2-EQU#show hw-inventory details
This is node 1643 of type 8609 and subrack address 0.
    unit in slot 1 is part of inventory and UP AND RUNNING
        unit 1 of width 1 has serial number 40601444713, CLEI code IPMVU00DRB
        top level serial number 40601445792
        manufacturing date 2016-3-30, 4:42:19.0, +0:00
        part# 82.86S-8609-R6 rev C
        HW type sbb2284-8609(2284) v3.0.1 SW type 0 v2.0.331
            Pmax=70.0W, Ptyp=60.0W
        infomodel FP2.0 (2.2.0); internal SW v.2.0.331
            Supported infomodels:
                FP2.0 (2.2.0)
        CPLD active revision: 0x0130
        WPIF expected and active revision: 0x001a
        LMIF expected and active revision: 0x0023
        TOCK expected and active revision: 0x0416
        module IF0 (LEFT) of type 4*100/1000BASE-X(9094)
            SFP connector 0 data:
                [0] type of serial transceiver: 3 (SFP transceiver)
                [1] extended identifier of type of serial transceiver: 4
                [2] connector type: 7(LC)
                [3] infiniband compliance code: 0
                [4] sonet compliance code4: 0
                [5] sonet compliance code5: 0
                [6] gigabit ethernet compliance code: 2, 1000BASE-LX
                [11] serial encoding type: 1 8B10B
                [14] link length for 9/125mm fiber (km): 52
                [15] link length for 9/125mm fiber (100m): 255
                [16] link length for 50/125mm fiber (10m): 0
                [17] link length for 62.5/125mm fiber (10m): 0
                [18] link length for copper (m): 0
                [20] vendor name: FINISAR CORP.
                [37] vendor organizationally unique: 36965
                [40] vendor part number: FTLF1419P1BCL-TL
                [56] vendor revision number: A
                [60] Laser wavelength: 1310 nm
                [62] reserved field: 0
                [68] vendor serial number: PU117T5
                [84] vendor's date (yy-mm-dd): 15-07-03
                [90] vendor's date (vendor specific part):
                [224-241] Tellabs part number: 81.86T-S001-13S-R6
                [242-243] Tellabs revision:  A
                [244-253] Tellabs CLEI code:  IPU3AVSKAA
                [255] Tellabs checksum: 0x3C
                [d102] Tx power: 2.6 dBm (1.8 mW)
                [d104] Rx power: -7.8 dBm (0.17 mW)
            SFP connector 1 is not present
            SFP connector 2 is not present
            SFP connector 3 is not present
        module IF1 (MIDDLE LEFT) of type 4*100/1000BASE-X(9094)
            SFP connector 0 data:
                [0] type of serial transceiver: 3 (SFP transceiver)
                [1] extended identifier of type of serial transceiver: 4
                [2] connector type: 7(LC)
                [3] infiniband compliance code: 0
                [4] sonet compliance code4: 0
                [5] sonet compliance code5: 0
                [6] gigabit ethernet compliance code: 2, 1000BASE-LX
                [11] serial encoding type: 1 8B10B
                [14] link length for 9/125mm fiber (km): 40
                [15] link length for 9/125mm fiber (100m): 0
                [16] link length for 50/125mm fiber (10m): 0
                [17] link length for 62.5/125mm fiber (10m): 0
                [18] link length for copper (m): 0
                [20] vendor name: HG GENUINE
                [37] vendor organizationally Connection closed by foreign host.

As you can see above, the error I am getting is Connection closed by foreign host and I can not get the full output of the show hw-inventory details command, not sure if the size of the output could be affecting this.

As the only resource I know for debugging this expect script is adding the -d flag I have run exactly the same script with that option in case we can get an idea about what is going on here.

$ expect -df ./runCommands.exp
expect version 5.45
argv[0] = expect  argv[1] = -df  argv[2] = ./runCommands.exp
set argc 0
set argv0 "./runCommands.exp"
set argv ""
executing commands from command file ./runCommands.exp
spawn telnet 10.220.64.67
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {15767}

expect: does "" (spawn_id exp6) match glob pattern ">"? no
Trying 10.220.64.67...

expect: does "Trying 10.220.64.67...\r\r\n" (spawn_id exp6) match glob pattern ">"? no
Connected to 10.220.64.67.
Escape character is '^]'.

expect: does "Trying 10.220.64.67...\r\r\nConnected to 10.220.64.67.\r\r\nEscape character is '^]'.\r\r\n" (spawn_id exp6) match glob pattern ">"? no

******************************************************************
*                                                                *
*                  Tellabs 8609 Network Element                  *
*                                                                *
*     Copyright (c) 2004-2015 Tellabs. All rights reserved.      *
*                                                                *
******************************************************************
Enter configuration commands, one per line. End with ^Z
HENKEL_CAPITAL_2-EQU>
expect: does "Trying 10.220.64.67...\r\r\nConnected to 10.220.64.67.\r\r\nEscape character is '^]'.\r\r\n\r\r\n******************************************************************\r\r\n*                                                                *\r\r\n*                  Tellabs 8609 Network Element                  *\r\r\n*                                                                *\r\r\n*     Copyright (c) 2004-2015 Tellabs. All rights reserved.      *\r\r\n*                                                                *\r\r\n******************************************************************\r\r\nEnter configuration commands, one per line. End with ^Z\r\nHENKEL_CAPITAL_2-EQU>" (spawn_id exp6) match glob pattern ">"? yes
expect: set expect_out(0,string) ">"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "Trying 10.220.64.67...\r\r\nConnected to 10.220.64.67.\r\r\nEscape character is '^]'.\r\r\n\r\r\n******************************************************************\r\r\n*                                                                *\r\r\n*                  Tellabs 8609 Network Element                  *\r\r\n*                                                                *\r\r\n*     Copyright (c) 2004-2015 Tellabs. All rights reserved.      *\r\r\n*                                                                *\r\r\n******************************************************************\r\r\nEnter configuration commands, one per line. End with ^Z\r\nHENKEL_CAPITAL_2-EQU>"
send: sending "enable\r" to { exp6 }

expect: does "" (spawn_id exp6) match glob pattern "#"? no
HENKEL_CAPITAL_2-EQU>
expect: does "\r                     \u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008HENKEL_CAPITAL_2-EQU>" (spawn_id exp6) match glob pattern "#"? no
enable

expect: does "\r                     \u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008HENKEL_CAPITAL_2-EQU>enable\r\n" (spawn_id exp6) match glob pattern "#"? no
HENKEL_CAPITAL_2-EQU#
expect: does "\r                     \u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008HENKEL_CAPITAL_2-EQU>enable\r\nHENKEL_CAPITAL_2-EQU#" (spawn_id exp6) match glob pattern "#"? yes
expect: set expect_out(0,string) "#"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "\r                     \u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008HENKEL_CAPITAL_2-EQU>enable\r\nHENKEL_CAPITAL_2-EQU#"
send: sending "terminal length 200\r" to { exp6 }

expect: does "" (spawn_id exp6) match glob pattern "#"? no
terminal length 200

expect: does "terminal length 200\r\n" (spawn_id exp6) match glob pattern "#"? no
HENKEL_CAPITAL_2-EQU#
expect: does "terminal length 200\r\nHENKEL_CAPITAL_2-EQU#" (spawn_id exp6) match glob pattern "#"? yes
expect: set expect_out(0,string) "#"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "terminal length 200\r\nHENKEL_CAPITAL_2-EQU#"
send: sending "terminal more off\r" to { exp6 }

expect: does "" (spawn_id exp6) match glob pattern "#"? no
terminal more off

expect: does "terminal more off\r\n" (spawn_id exp6) match glob pattern "#"? no
HENKEL_CAPITAL_2-EQU#
expect: does "terminal more off\r\nHENKEL_CAPITAL_2-EQU#" (spawn_id exp6) match glob pattern "#"? yes
expect: set expect_out(0,string) "#"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "terminal more off\r\nHENKEL_CAPITAL_2-EQU#"
send: sending "show hw-inventory details\r" to { exp6 }

expect: does "" (spawn_id exp6) match glob pattern "#"? no
show hw-inventory details

expect: does "show hw-inventory details\r\n" (spawn_id exp6) match glob pattern "#"? no
This is node 1643 of type 8609 and subrack address 0.
    unit in slot 1 is pa
expect: does "show hw-inventory details\r\nThis is node 1643 of type 8609 and subrack address 0.\r\n    unit in slot 1 is pa" (spawn_id exp6) match glob pattern "#"? no
r
expect: does "show hw-inventory details\r\nThis is node 1643 of type 8609 and subrack address 0.\r\n    unit in slot 1 is par" (spawn_id exp6) match glob pattern "#"? no
t of inventory and UP AND RUNNING
        unit 1 of width 1 has serial number 4
expect: does "show hw-inventory details\r\nThis is node 1643 of type 8609 and subrack address 0.\r\n    unit in slot 1 is part of inventory and UP AND RUNNING\r\n        unit 1 of width 1 has serial number 4" (spawn_id exp6) match glob pattern "#"? no
0601444713, CLEI code IPMVU00DRB
        top level serial number 40601445792
        manufacturing date 2016-3-30, 4:42:19.0, +0:00
        part# 82.86S-8609
expect: does "show hw-inventory details\r\nThis is node 1643 of type 8609 and subrack address 0.\r\n    unit in slot 1 is part of inventory and UP AND RUNNING\r\n        unit 1 of width 1 has serial number 40601444713, CLEI code IPMVU00DRB\r\n        top level serial number 40601445792\r\n        manufacturing date 2016-3-30, 4:42:19.0, +0:00\r\n        part# 82.86S-8609" (spawn_id exp6) match glob pattern "#"? yes
expect: set expect_out(0,string) "#"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "show hw-inventory details\r\nThis is node 1643 of type 8609 and subrack address 0.\r\n    unit in slot 1 is part of inventory and UP AND RUNNING\r\n        unit 1 of width 1 has serial number 40601444713, CLEI code IPMVU00DRB\r\n        top level serial number 40601445792\r\n        manufacturing date 2016-3-30, 4:42:19.0, +0:00\r\n        part#"
send: sending "exit\r" to { exp6 }
-R6 rev C
        HW type sbb2284-8609(2284) v3.0.1 SW type 0 v2.0.331
            Pmax=70.0W, Ptyp=60.0W
        infomodel FP2.0 (2.2.0); internal SW v.2.0.331
            Supported infomodels:
                FP2.0 (2.2.0)
        CPLD active revision: 0x0130
        WPIF expected and active revision: 0x001a
        LMIF expected and active revision: 0x0023
        TOCK expected and active revision: 0x0416
        module IF0 (LEFT) of type 4*100/1000BASE-X(9094)
            SFP connector 0 data:
                [0] type of serial transceiver: 3 (SFP transceiver)
                [1] extended identifier of type of serial transceiver: 4
                [2] connector type: 7(LC)
                [3] infiniband compliance code: 0
                [4] sonet compliance code4: 0
                [5] sonet compliance code5: 0
                [6] gigabit ethernet compliance code: 2, 1000BASE-LX
                [11] serial encoding type: 1 8B10B
                [14] link length for 9/125mm fiber (km): 52
                [15] link length for 9/125mm fiber (100m): 255
                [16] link length for 50/125mm fiber (10m): 0
                [17] link length for 62.5/125mm fiber (10m): 0
                [18] link length for copper (m): 0
                [20] vendor name: FINISAR CORP.
                [37] vendor organizationally unique: 36965
                [40] vendor part number: FTLF1419P1BCL-TL
                [56] vendor revision number: A
                [60] Laser wavelength: 1310 nm
                [62] reserved field: 0
                [68] vendor serial number: PU117T5
                [84] vendor's date (yy-mm-dd): 15-07-03
                [90] vendor's date (vendor specific part):
                [224-241] Tellabs part number: 81.86T-S001-13S-R6
                [242-243] Tellabs revision:  A
                [244-253] Tellabs CLEI code:  IPU3AVSKAA
                [255] Tellabs checksum: 0x3C
                [d102] Tx power: 2.6 dBm (1.8 mW)
                [d104] Rx power: -7.7 dBm (0.17 mW)
            SFP connector 1 is not present
            SFP connector 2 is not present
            SFP connector 3 is not present
        module IF1 (MIDDLE LEFT) of type 4*100/1000BASE-X(9094)
            SFP connector 0 data:
                [0] type of serial transceiver: 3 (SFP transceiver)
                [1] extended identifier of type of serial transceiver: 4
                [2] connector type: 7(LC)
                [3] infiniband compliance code: 0
                [4] sonet compliance code4: 0
                [5] sonet compliance code5: 0
                [6] gigabit ethernet compliance code: 2, 1000BASE-LX
                [11] serial encoding type: 1 8B10B
                [14] link length for 9/125mm fiber (km): 40
                [15] link length for 9/125mm fiber (100m): 0
                [16] link length for 50/125mm fiber (10m): 0
                [17] link length for 62.5/125mm fiber (10m): 0
                [18] link length for copper (m): 0
                [20] vendor name: HG GENUINE
                [37] vendor organizationally unique: 0
                [40] vendor part number: MXPD-243MD
                [56] vendor revision number:
                [60] Laser wavelength: 1310 nm
                [62] reserved field: 0
                [68] vendor serial number: ME12112000011
                [84] vendor's date (yy-mm-dd): 12-03-17
                [90] vendor's date (vendor specific part):
                [224-255] vendor specific ID field : 0x00000000
                    0x00000000 0x00000000 0x00000000 0x00000000
                    0x00000000 0x00000000 0x00000000
                [d102] Tx power: -3.0 dBm (0.50 mW)
                [d104] Rx power: -13 dBm (50 uW)
            SFP connector 1 is not present
            SFP connector 2 is Connection closed by foreign host.
expect: read eof
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) " 82.86S-8609-R6 rev C\r\n        HW type sbb2284-8609(2284) v3.0.1 SW type 0 v2.0.331\r\n            Pmax=70.0W, Ptyp=60.0W\r\n        infomodel FP2.0 (2.2.0); internal SW v.2.0.331\r\n            Supported infomodels:\r\n                FP2.0 (2.2.0)\r\n        CPLD active revision: 0x0130\r\n        WPIF expected and active revision: 0x001a\r\n        LMIF expected and active revision: 0x0023\r\n        TOCK expected and active revision: 0x0416\r\n        module IF0 (LEFT) of type 4*100/1000BASE-X(9094)\r\n            SFP connector 0 data:\r\n                [0] type of serial transceiver: 3 (SFP transceiver)\r\n                [1] extended identifier of type of serial transceiver: 4\r\n                [2] connector type: 7(LC)\r\n                [3] infiniband compliance code: 0\r\n                [4] sonet compliance code4: 0\r\n                [5] sonet compliance code5: 0\r\n                [6] gigabit ethernet compliance code: 2, 1000BASE-LX\r\n                [11] serial encoding type: 1 8B10B\r\n                [14] link length for 9/125mm fiber (km): 52\r\n                [15] link length for 9/125mm fiber (100m): 255\r\n                [16] link length for 50/125mm fiber (10m): 0\r\n                [17] link length for 62.5/125mm fiber (10m): 0\r\n                [18] link length for copper (m): 0\r\n                [20] vendor name: FINISAR CORP.   \r\n                [37] vendor organizationally unique: 36965\r\n                [40] vendor part number: FTLF1419P1BCL-TL\r\n                [56] vendor revision number: A   \r\n                [60] Laser wavelength: 1310 nm\r\n                [62] reserved field: 0\r\n                [68] vendor serial number: PU117T5         \r\n                [84] vendor's date (yy-mm-dd): 15-07-03\r\n                [90] vendor's date (vendor specific part):   \r\n                [224-241] Tellabs part number: 81.86T-S001-13S-R6\r\n                [242-243] Tellabs revision:  A \r\n                [244-253] Tellabs CLEI code:  IPU3AVSKAA\r\n                [255] Tellabs checksum: 0x3C\r\n                [d102] Tx power: 2.6 dBm (1.8 mW)\r\n                [d104] Rx power: -7.7 dBm (0.17 mW)\r\n            SFP connector 1 is not present\r\n            SFP connector 2 is not present\r\n            SFP connector 3 is not present\r\n        module IF1 (MIDDLE LEFT) of type 4*100/1000BASE-X(9094)\r\n            SFP connector 0 data:\r\n                [0] type of serial transceiver: 3 (SFP transceiver)\r\n                [1] extended identifier of type of serial transceiver: 4\r\n                [2] connector type: 7(LC)\r\n                [3] infiniband compliance code: 0\r\n                [4] sonet compliance code4: 0\r\n                [5] sonet compliance code5: 0\r\n                [6] gigabit ethernet compliance code: 2, 1000BASE-LX\r\n                [11] serial encoding type: 1 8B10B\r\n                [14] link length for 9/125mm fiber (km): 40\r\n                [15] link length for 9/125mm fiber (100m): 0\r\n                [16] link length for 50/125mm fiber (10m): 0\r\n                [17] link length for 62.5/125mm fiber (10m): 0\r\n                [18] link length for copper (m): 0\r\n                [20] vendor name: HG GENUINE      \r\n                [37] vendor organizationally unique: 0\r\n                [40] vendor part number: MXPD-243MD      \r\n                [56] vendor revision number: \r\n                [60] Laser wavelength: 1310 nm\r\n                [62] reserved field: 0\r\n                [68] vendor serial number: ME12112000011   \r\n                [84] vendor's date (yy-mm-dd): 12-03-17\r\n                [90] vendor's date (vendor specific part):   \r\n                [224-255] vendor specific ID field : 0x00000000 \r\n                    0x00000000 0x00000000 0x00000000 0x00000000 \r\n                    0x00000000 0x00000000 0x00000000 \r\n                [d102] Tx power: -3.0 dBm (0.50 mW)\r\n                [d104] Rx power: -13 dBm (50 uW)\r\n            SFP connector 1 is not present\r\n            SFP connector 2 is Connection closed by foreign host.\r\r\n"

Do you think this could be an issue with the expect script itself or there could be something else related to the telnet device?

If you are willing to do so we can have a screen session and we can work together on this, at this point I feel desperate about this weird issue, not sure how to keep moving forward.

This is the full expected output:

$ telnet 10.220.64.67
Trying 10.220.64.67...
Connected to 10.220.64.67.
Escape character is '^]'.

******************************************************************
*                                                                *
*                  Tellabs 8609 Network Element                  *
*                                                                *
*     Copyright (c) 2004-2015 Tellabs. All rights reserved.      *
*                                                                *
******************************************************************
Enter configuration commands, one per line. End with ^Z
HENKEL_CAPITAL_2-EQU>enable
HENKEL_CAPITAL_2-EQU#show hw-inventory details
This is node 1643 of type 8609 and subrack address 0.
    unit in slot 1 is part of inventory and UP AND RUNNING
        unit 1 of width 1 has serial number 40601444713, CLEI code IPMVU00DRB
        top level serial number 40601445792
        manufacturing date 2016-3-30, 4:42:19.0, +0:00
        part# 82.86S-8609-R6 rev C
        HW type sbb2284-8609(2284) v3.0.1 SW type 0 v2.0.331
            Pmax=70.0W, Ptyp=60.0W
        infomodel FP2.0 (2.2.0); internal SW v.2.0.331
            Supported infomodels:
                FP2.0 (2.2.0)
        CPLD active revision: 0x0130
        WPIF expected and active revision: 0x001a
        LMIF expected and active revision: 0x0023
        TOCK expected and active revision: 0x0416
        module IF0 (LEFT) of type 4*100/1000BASE-X(9094)
            SFP connector 0 data:
                [0] type of serial transceiver: 3 (SFP transceiver)
                [1] extended identifier of type of serial transceiver: 4
                [2] connector type: 7(LC)
                [3] infiniband compliance code: 0
                [4] sonet compliance code4: 0
                [5] sonet compliance code5: 0
                [6] gigabit ethernet compliance code: 2, 1000BASE-LX
                [11] serial encoding type: 1 8B10B
                [14] link length for 9/125mm fiber (km): 52
                [15] link length for 9/125mm fiber (100m): 255
                [16] link length for 50/125mm fiber (10m): 0
                [17] link length for 62.5/125mm fiber (10m): 0
                [18] link length for copper (m): 0
                [20] vendor name: FINISAR CORP.
                [37] vendor organizationally unique: 36965
                [40] vendor part number: FTLF1419P1BCL-TL
                [56] vendor revision number: A
                [60] Laser wavelength: 1310 nm
                [62] reserved field: 0
                [68] vendor serial number: PU117T5
                [84] vendor's date (yy-mm-dd): 15-07-03
                [90] vendor's date (vendor specific part):
                [224-241] Tellabs part number: 81.86T-S001-13S-R6
                [242-243] Tellabs revision:  A
                [244-253] Tellabs CLEI code:  IPU3AVSKAA
                [255] Tellabs checksum: 0x3C
                [d102] Tx power: 2.6 dBm (1.8 mW)
                [d104] Rx power: -7.7 dBm (0.17 mW)
            SFP connector 1 is not present
            SFP connector 2 is not present
            SFP connector 3 is not present
        module IF1 (MIDDLE LEFT) of type 4*100/1000BASE-X(9094)
            SFP connector 0 data:
                [0] type of serial transceiver: 3 (SFP transceiver)
                [1] extended identifier of type of serial transceiver: 4
                [2] connector type: 7(LC)
                [3] infiniband compliance code: 0
                [4] sonet compliance code4: 0
                [5] sonet compliance code5: 0
                [6] gigabit ethernet compliance code: 2, 1000BASE-LX
                [11] serial encoding type: 1 8B10B
                [14] link length for 9/125mm fiber (km): 40
                [15] link length for 9/125mm fiber (100m): 0
                [16] link length for 50/125mm fiber (10m): 0
                [17] link length for 62.5/125mm fiber (10m): 0
                [18] link length for copper (m): 0
                [20] vendor name: HG GENUINE
                [37] vendor organizationally unique: 0
                [40] vendor part number: MXPD-243MD
                [56] vendor revision number:
                [60] Laser wavelength: 1310 nm
                [62] reserved field: 0
                [68] vendor serial number: ME12112000011
                [84] vendor's date (yy-mm-dd): 12-03-17
                [90] vendor's date (vendor specific part):
                [224-255] vendor specific ID field : 0x00000000
                    0x00000000 0x00000000 0x00000000 0x00000000
                    0x00000000 0x00000000 0x00000000
                [d102] Tx power: -3.0 dBm (0.50 mW)
                [d104] Rx power: -13 dBm (50 uW)
            SFP connector 1 is not present
            SFP connector 2 is not present
            SFP connector 3 is not present
        module IF2 (MIDDLE) of type 4*10/100/1000BASE-T(9093)
        module IF3 (RIGHT MIDDLE) of type 8*10/100BASE-TX-LM(2243) v2.0.1 (hot insert)
            serial number 40601373354, CLEI code IPU3A7TKAA
            top level serial number 40601376329
            manufacturing date 2015-10-20, 8:51:59.0, +0:00
            part# 81.86LFETX82243-R6 rev D
            Pmax=4.60W, Ptyp=4.00W
        module IF4 (RIGHT) of type 8*10/100BASE-TX-LM(2243) v2.0.1 (hot insert)
            serial number 40601405399, CLEI code IPU3A7TKAA
            top level serial number 40601405948
            manufacturing date 2015-12-31, 0:06:43.0, +0:00
            part# 81.86LFETX82243-R6 rev D
            Pmax=4.60W, Ptyp=4.00W
        module COOLING FAN 1 of type fmb2285-coolingFan(2285)
        module PRIMARY POWER of type -48Vdc(2264)(2264) v2.0.0
            serial number 40601425507, CLEI code IPUPAKMLAA
            top level serial number 40601430234
            manufacturing date 2016-2-26, 17:02:48.9, +8:00
            part# 81.86P-0911DC48-R6 rev C
            Pmax=0.00W, Ptyp=0.00W
        module OVEN CONTROLLED OSCILLATOR of type vid9096-ocxo(9096) v1.0.0
        interface module 0 has
            expected type 4*100/1000BASE-X
            active   type 4*100/1000BASE-X
            existing type 4*100/1000BASE-X
            mode is not relevant
        interface module 1 has
            expected type 4*100/1000BASE-X
            active   type 4*100/1000BASE-X
            existing type 4*100/1000BASE-X
            mode is not relevant
        interface module 2 has
            expected type 4*10/100/1000BASE-T
            active   type 4*10/100/1000BASE-T
            existing type 4*10/100/1000BASE-T
            mode is not relevant
        interface module 3 has
            expected type 8*10/100BASE-TX-LM
            active   type 8*10/100BASE-TX-LM
            existing type 8*10/100BASE-TX-LM
            mode is not relevant
            Pmax=4.60W, Ptyp=4.00W
        interface module 4 has
            expected type 8*10/100BASE-TX-LM
            active   type 8*10/100BASE-TX-LM
            existing type 8*10/100BASE-TX-LM
            mode is not relevant
            Pmax=4.60W, Ptyp=4.00W
        power module primary has
            expected type -48Vdc(2264)
            active   type -48Vdc(2264)
            existing type -48Vdc(2264)
            mode is not relevant
            Pmax=0.00W, Ptyp=0.00W
        oven controlled oscillator has
            expected type vid9096-ocxo
            active   type vid9096-ocxo
            existing type vid9096-ocxo
            mode is not relevant

HENKEL_CAPITAL_2-EQU#exit
Connection closed by foreign host.

In the previous output, I entered the commands manually and it worked correctly the only difference is that I did not use the terminal more off and terminal length 200 commands.

$ telnet 10.220.64.67
Enter configuration commands, one per line. End with ^Z
HENKEL_CAPITAL_2-EQU>enable
HENKEL_CAPITAL_2-EQU#show hw-inventory details
**[short output... due to the limit of the stackoverflow text box]**
--More--
            mode is not relevant
HENKEL_CAPITAL_2-EQU#exit
Connection closed by foreign host.

When I see the --More-- string I just type the space bar in order to get more output until the last prompt HENKEL_CAPITAL_2-EQU# is shown, then I just type the exit command.

Body:
Your main problem seems to be that you are interleaving code (especially those sleep 1s!) at different levels, resulting in a script that's actually pure gibberish. That the code isn't crashing is pure happenstance.

Rewriting the section with the problems while taking a guess as to what you need...

# Handle login
expect {
    "user name:" {
        send "$user\r"
        exp_continue; # keep waiting
    }
    "password:" {
        send "$password\r"
        exp_continue; # keep waiting
    }
    ">" {
        # Got a logged-in prompt so stop waiting (by not exp_continuing)
    }
}

# Handle what's going on remotely; note that we've a prompt at this point
# and can use simple challenge/response coding from here on
set prompt "# "
send "enable\r"
expect $prompt
send "terminal length 200\r"
expect $prompt
send "terminal more off\r"
foreach cmd $commands {
    expect $prompt
    send "$cmd\r"
}
expect $prompt
send "exit\r"
expect eof

This technique becomes more valuable once you add in error handling rather than trusting everything to work, as one of the main powers of expect is being able to wait for several things at once. You don't usually need that, but it's super-valuable when you do!

You don't normally need to add in sleep calls, not when you're just sending a command an waiting for the prompt back.


问:
How to generate three unequal numbers?
Here the number generation :

```<code>for( int i=0; i<3; i++) {
    int randomNumbers = random.nextInt(10) + 1;
}
</code>```

And here I can receive the same digits.

For example: 5,7,5;

But I need to receive only different numbers: 5,1,9.

Is it possible maybe with some little piece of code or I should write some method for it?

答: In my point of view, using a while loop is possible to generate random numbers with different digits. Use while loop to check whether the number was generated earlier and if it was then generate new number.</p>

Title: How to generate three unequal numbers?

Body:
Here the number generation :

for( int i=0; i<3; i++) {
    int randomNumbers = random.nextInt(10) + 1;
}

And here I can receive the same digits.

For example: 5,7,5;

But I need to receive only different numbers: 5,1,9.

Is it possible maybe with some little piece of code or I should write some method for it?


问:
Batch converting .eps to .jpg in imagemagick and making .mkv
I am trying to convert multiple .eps files into .jpg ones. By looking at answers here in SO, I was able to do it for single separate files.

The problem is that, when I'm trying to do it for all the files, they don't show any .jpg file.

I am currently using Imagemagick with the command

convert -density 300 outputs-000.eps -flatten outputs-000.jpg```
</div>
</div>
</p>

<p>I believe the problem is because my files are written as </p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>outputs-000.eps
outputs-001.eps
outputs-002.eps
outputs-003.eps
...
outputs-145.eps
...</code>```

and so on. I tried putting %d (as in outputs-%d.eps and outputs-%d.jpg), but with no success.

Apart from that, I intent to get all those files and "convert" them into an .mkv or .gif or similar type (they are images of the time configuration of a particle collision system, so each image is a frame, so the goal is to make it into a 10sec movie). If there is a way to do that directly from the .eps, even better. Any help is welcome, since I've been trying to do this for several hours now. Thank you.

答:
For anyone who lands here trying to figure out how to work around ImageMagic's convert: not authorized without reverting the change that was made to the system-wide security policy to close a vulnerability, here's how you'd use Ghostscript to do a batch EPS-to-JPEG conversion directly without bringing ImageMagick into the mix:

gs -dSAFER -dEPSCrop -r300 -sDEVICE=jpeg -o outputs-%03d.jpg outputs-*.eps
```

<ul>
<li><code>-dSAFER</code> puts Ghostscript in a sandboxed mode where Postscript code can only interact with the files you specified on the command line. (Yes, the parts of EPS, PS, and PDF files that define the page contents are in a turing-complete programming language.)</li>
<li><code>-dEPSCrop</code> asks for the rendered output to be cropped to the bounding box of the drawing rather than padded out to whatever size page Ghostscript expects you to be printing to. (See the manual for details.)</li>
<li>The <code>-r300</code> requests 300 DPI (<code>-r600</code> for 600 DPI, etc.)</li>
<li>The <code>-sDEVICE</code> specifies the output format (See the Devices section of the manual for other choices.)</li>
<li><code>-o</code> is a shorthand for <code>-dBATCH -dNOPAUSE -sOutputFile=</code></li>
<li>This section of the Ghostscript manual gives some example formats for for multi-file filename output but, for the actual syntax definition, it points you at the documentation for the C printf(3) function.</li>
</ul>

<p>Once you've got your JPEGs, you can follow the instructions in this answer over on the Video Production Stack Exchange to combine them into an MKV file.</p>

<p>The TL;DR is this command here:</p>

```ffmpeg -framerate 30 -i outputs-%03d.jpg -codec copy output.mkv
```

Check out the other answers if you want something that performs inter-frame compression rather than aiming to avoid transcoding the JPEGs again.

(If you want the best compromise, have Ghostscript output PNGs and then let ffmpeg handle switching to lossy compression.)

Body:
I am trying to convert multiple .eps files into .jpg ones. By looking at answers here in SO, I was able to do it for single separate files.

The problem is that, when I'm trying to do it for all the files, they don't show any .jpg file.

I am currently using Imagemagick with the command

convert -density 300 outputs-000.eps -flatten outputs-000.jpg

I believe the problem is because my files are written as

outputs-000.eps
outputs-001.eps
outputs-002.eps
outputs-003.eps
...
outputs-145.eps
...

and so on. I tried putting %d (as in outputs-%d.eps and outputs-%d.jpg), but with no success.

Apart from that, I intent to get all those files and "convert" them into an .mkv or .gif or similar type (they are images of the time configuration of a particle collision system, so each image is a frame, so the goal is to make it into a 10sec movie). If there is a way to do that directly from the .eps, even better. Any help is welcome, since I've been trying to do this for several hours now. Thank you.

Body:
For anyone who lands here trying to figure out how to work around ImageMagic's convert: not authorized without reverting the change that was made to the system-wide security policy to close a vulnerability, here's how you'd use Ghostscript to do a batch EPS-to-JPEG conversion directly without bringing ImageMagick into the mix:

gs -dSAFER -dEPSCrop -r300 -sDEVICE=jpeg -o outputs-%03d.jpg outputs-*.eps

-dSAFER puts Ghostscript in a sandboxed mode where Postscript code can only interact with the files you specified on the command line. (Yes, the parts of EPS, PS, and PDF files that define the page contents are in a turing-complete programming language.)

-dEPSCrop asks for the rendered output to be cropped to the bounding box of the drawing rather than padded out to whatever size page Ghostscript expects you to be printing to. (See the manual for details.)

The -r300 requests 300 DPI (-r600 for 600 DPI, etc.)

The -sDEVICE specifies the output format (See the Devices section of the manual for other choices.)

-o is a shorthand for -dBATCH -dNOPAUSE -sOutputFile=

This section of the Ghostscript manual gives some example formats for for multi-file filename output but, for the actual syntax definition, it points you at the documentation for the C printf(3) function.

Once you've got your JPEGs, you can follow the instructions in this answer over on the Video Production Stack Exchange to combine them into an MKV file.

The TL;DR is this command here:

ffmpeg -framerate 30 -i outputs-%03d.jpg -codec copy output.mkv

Check out the other answers if you want something that performs inter-frame compression rather than aiming to avoid transcoding the JPEGs again.

(If you want the best compromise, have Ghostscript output PNGs and then let ffmpeg handle switching to lossy compression.)


问:
Add 2 Line-By-Line text readers in one function
I want to read 2 different text files, the keys.txt file and the proxies.txt file. When reading keys.txt start a function and read proxies.txt to add something in that function.

```<code>var LineByLineReader = require('line-by-line'),
    lr = new LineByLineReader('keys.txt');
    ls = new LineByLineReader('proxies.txt')

lr.on('line', function (line) {
    console.log(chalk.blueBright("Going next to: " + line))
    lr.pause();
     x = x+1  //ignore this, it is my max readers per second
    if(x<=10){
        try {
    (async () => {
       ls.on('line', proxy) .then(proxy => {
        const browser = await puppeteer.launch({headless: true, devtools: false,
            args: [`--proxy-server=http://${proxy}`]
        })
        const page = await browser.newPage()

       })})} catch(err) {throw(err)}}})
</code>```

I need to use the lines from proxies.txt into my code, however I can't do it because it starts 2 separate functions. (if I use ls.on('line', function proxy { CODE })). The line  ls.on('line', proxy) .then(proxy => { doesn't seem like working for some reason.

答:
I did it. I used

```<code>ls.on('line', (proxy) => {
    ls.pause();
</code>```

Before the code. Now for each line it reads both text files line by line, and executes the function I need.

Body:
I want to read 2 different text files, the keys.txt file and the proxies.txt file. When reading keys.txt start a function and read proxies.txt to add something in that function.

var LineByLineReader = require('line-by-line'),
    lr = new LineByLineReader('keys.txt');
    ls = new LineByLineReader('proxies.txt')

lr.on('line', function (line) {
    console.log(chalk.blueBright("Going next to: " + line))
    lr.pause();
     x = x+1  //ignore this, it is my max readers per second
    if(x<=10){
        try {
    (async () => {
       ls.on('line', proxy) .then(proxy => {
        const browser = await puppeteer.launch({headless: true, devtools: false,
            args: [`--proxy-server=http://${proxy}`]
        })
        const page = await browser.newPage()

       })})} catch(err) {throw(err)}}})

I need to use the lines from proxies.txt into my code, however I can't do it because it starts 2 separate functions. (if I use ls.on('line', function proxy { CODE })). The line  ls.on('line', proxy) .then(proxy => { doesn't seem like working for some reason.

Body:
I did it. I used

ls.on('line', (proxy) => {
    ls.pause();

Before the code. Now for each line it reads both text files line by line, and executes the function I need.


问:
How to automatically include some where conditions in rails model?
I have several models with office_id, fiscal_year_id attributes. I want these field to automatically set before querying. So, I don't have to care about data overlapping from one office to another and one fiscal year to another.

答:
app/models/concern/fiscalable.rb

```<code>module Fiscalable
  extend ActiveSupport::Concern

  def office_id
    super || 1 # default office_id
  end

  def fiscal_year_id
    super || Time.zone.now.year
  end
end
</code>```

And in your models.

```<code>class Model < ActiveRecord
  include Fiscalable
  ...
end
</code>```

In views.

```<code><%= @object.fiscal_year_id %>
</code>```

Body:
app/models/concern/fiscalable.rb

module Fiscalable
  extend ActiveSupport::Concern

  def office_id
    super || 1 # default office_id
  end

  def fiscal_year_id
    super || Time.zone.now.year
  end
end

And in your models.

class Model < ActiveRecord
  include Fiscalable
  ...
end

In views.

<%= @object.fiscal_year_id %>