【发布时间】:2020-06-08 20:29:40
【问题描述】:
我正在尝试在pexpect sendline 中调用sleep 10 命令。但是,pexpect 不会等待睡眠完成。
以下是可用于重现问题的示例。
import pexpect
import sys
child = pexpect.spawn('bash', encoding='utf-8')
child.logfile = sys.stdout
child.expect('~')
child.sendline("date");
child.expect('2020')
child.sendline('sleep 10')
child.expect('~',timeout=12)
child.sendline('date')
注意:
我已经知道使用
time.sleep()函数,但是在我的要求中有一个限制(bash 命令和预期输出从一些不同的工具发送到 python 代码),这使得从 bash 使用睡眠只要。此示例只是该问题的缩小版本。将
~更改为您的 bash 提示符以重现该问题。
【问题讨论】: