预期预期(pexpect.EOF公司)抛出异常而不输出

2024-09-30 18:29:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是python2.7和pexpect 4.6.0

根据pexpectdocs

If you wish to read up to the end of the child’s output without generating an EOF exception then use the expect(pexpect.EOF) method.

但当我这么做时,它会引发EOF异常。我如何期望EOF并获得子级返回的所有输出?在

child = pexpect.spawn("ssh user@server")
child.expect("[pP]assword")
child.sendline("password")
child.expect("\$")
print child.before + child.after
child.sendline("ifconfig")
child.expect(pexpect.EOF)    # this throws Exception

文件中还说:

Some UNIX platforms will throw an exception when you try to read from a file descriptor in the EOF state. Other UNIX platforms instead quietly return an empty string to indicate that the EOF state has been reached.

我们怎么知道这是不是问题?有什么解决办法呢?在


Tags: thetoyouanchildreadexceptionunix