如何解决使用 Pexpect.spawn() 执行 shell 脚本
我现有的 shell 脚本“installation.sh”需要用户输入作为安装的一部分,我试图用 python pexpect.spwan() 处理它,但是在执行脚本后,它总是停留在 pexpect.spawn() 进程中,因为脚本永远不会结束并且无法匹配任何用户输入。有没有更好的方法来处理它?感谢回复。
child = pexpect.spawn ('/opt/scripts/installation.sh')
for line in child:
print(line.decode().strip())
child.expect('\r\n')
print(child.expect('Do you need to configure DNS? y\|n \[n\] '))
print(line.decode().strip('\n'))
child.sendline('y\n')
child.expect('Input IP address of DNS server:')
print(line.decode().strip('\n'))
child.sendline('10.11.11.13\n')
child.expect('Do you need to configure more DNS servers?')
child.sendline('n')
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。