Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.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 交互式解析的预期失败?_Python_Pexpect - Fatal编程技术网

Python 交互式解析的预期失败?

Python 交互式解析的预期失败?,python,pexpect,Python,Pexpect,我正在尝试解析设备的启动序列。 我使用telnet连接到终端服务器,终端服务器将我连接到设备的串行端口 以下脚本工作并使我登录,这意味着终端响应脚本和发送线: import pexpect child = pexpect.spawn ('telnet x.x.x.x yyyy') child.expect ('login: ') child.sendline ('anonymous') child.expect ('Password:') child.sendline ('noah@exampl

我正在尝试解析设备的启动序列。 我使用telnet连接到终端服务器,终端服务器将我连接到设备的串行端口

以下脚本工作并使我登录,这意味着终端响应脚本和发送线:

import pexpect
child = pexpect.spawn ('telnet x.x.x.x yyyy')
child.expect ('login: ')
child.sendline ('anonymous')
child.expect ('Password:')
child.sendline ('noah@example.com')
以下操作失败:

import pexpect
child = pexpect.spawn ('telnet x.x.x.x yyyy')
child.expect ('Hit [Enter] to boot immediately, or space bar for command prompt.', timeout=300)
child.send ('\x20')
print child.before
我的目标是当设备启动时,它只是行向输出,我期望的字符串在滚动中间某个地方。

上述脚本无法匹配。
进一步调试后,“child.before”显示登录提示之前的最后一行。失败的原因是什么?

答对了!转义字符是我所缺少的。

[
]
对RE有特殊意义。尝试用
Hit\\[Enter]
替换
Hit\\[Enter]
.child.expect('Hit[Enter]立即启动\,或空格键用于命令提示。'),300)请提供此答案中缺少的明确代码,然后将此答案标记为已接受。需要使用类似以下内容:child.expect('Hit[Enter]立即启动\,或命令提示符的空格键。“,300)