pexpect-等待在继续之前完成命令
我目前的情况与pexpect。
child = pexpect.spawn(f"virsh console {hostname} --force", timeout=200, maxread=4000)
child.sendline("sudo config ztp disable -y")
child.send("\r")
print(" Waiting ZTP ")
sleep(120)
# rest of my script
现在我要在“睡眠(120)”之后睡觉
这个命令可以花1-2分钟才能完成, pexect脚本一旦禁用命令完成而不是固定睡眠时间。
I have a current situation with pexpect.
child = pexpect.spawn(f"virsh console {hostname} --force", timeout=200, maxread=4000)
child.sendline("sudo config ztp disable -y")
child.send("\r")
print(" Waiting ZTP ")
sleep(120)
# rest of my script
This command can take 1-2min to finish, now I'm doing a sleep after it "sleep(120)"
I would like to know if there is a way to perform it using pexpect arguments instead of sleep, so I can continue my pexect script as soon as the disable command finishes instead of having a fixed sleep time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试使用waitnoecho(),它适用于我的情况。 <如果您发现不同的工作解决方案,请与我分享。
You can try using waitnoecho(), it worked for my case. Here is the link for the docs. Share with me if you found different working solution.
使用
期望()
要关注命令的输出,并等待其成功完成的提示。Use
expect()
to watch the output of your command and wait for the prompt that follows its successful completion.