Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python telnetlib.read_,直到第二次匹配_Python_Telnetlib - Fatal编程技术网

Python telnetlib.read_,直到第二次匹配

Python telnetlib.read_,直到第二次匹配,python,telnetlib,Python,Telnetlib,我对python或任何语言都不熟悉,但我试图编写此脚本以方便执行某些任务,python telnetlib存在此问题,我试图使用.read_until(comm_prompt)读取ssh会话的输出,但它似乎总是匹配第一个提示,而不是最后一个,导致未显示实际输出,如下所示: while True: command = raw_input('Give me a command: ') expected = 'Switch#' tn.write(command+'\n')

我对python或任何语言都不熟悉,但我试图编写此脚本以方便执行某些任务,python telnetlib存在此问题,我试图使用
.read_until(comm_prompt)
读取ssh会话的输出,但它似乎总是匹配第一个提示,而不是最后一个,导致未显示实际输出,如下所示:

  while True:
    command = raw_input('Give me a command: ')
    expected = 'Switch#'
    tn.write(command+'\n')
    output = tn.read_until(expected)
    print output
这是一个很好的例子:

Give me a command: show version
Switch#

我想知道我该如何匹配第二个“开关”,或者也许还有其他方法。我想使用
.read\u until
方法的原因是因为速度。

只需添加另一个
read\u until(预期)
就可以了只需添加另一个
read\u until(预期)
就可以了