Paramiko capturing command output

前端 未结 3 1064
抹茶落季
抹茶落季 2020-12-22 06:37

I have an issue that has been giving me a headache for a few days. I am using the Paramiko module with Python 2.7.10 and I\'d like to issue multiple commands to a Brocade ro

3条回答
  •  遥遥无期
    2020-12-22 07:02

    For your second question: Though I am not specialist of paramiko, I see that function recv, according to the doc, returns a string. If you apply a for loop on a string, you will get characters (and not lines as one might perhaps expect). The newline is caused by your use of the print function as explained on this page, at paragraph 6.3.

    I haven't studied what paramiko suggests to do. But why don't you treat the full string as a single entity? For example, you could check the presence of "up" as:

    if "up" in output:
    

    Or, if that suits your needs better, you could split the string into lines and then do whatever test you want to do:

    for line in output.split('\n'): 
    

提交回复
热议问题