expect 脚本
循环执行
#!/usr/bin/expect set timeout -1 spawn /home/gostudy/gostudy expect { "请输入用户名" {send "123456\r"; exp_continue } "请输入密码" {send "123456\r"; exp_continue } "请输入AppletOpenId" {send "openid\r"; exp_continue } "请输入答题的正确率(1-100)" {send "65\r"; exp_continue } "4、乱序刷题" {send "4\r"; exp_continue } "刷题总数" {send "150\r"; exp_continue } "已经学习完啦!是否继续学习?(Yes/No)" {send "yes\r"; exp_continue } } expect eof
单步执行
#!/usr/bin/expect set timeout -1 spawn /home/gostudy/gostudy expect { 请输入用户名 {send "123456\r" } } expect { 请输入密码 {send "123456\r" } } expect { 请输入AppletOpenId {send "opendi\r" } } expect { 请输入答题的正确率(1-100) {send "65\r" } } expect { 4、乱序刷题 {send "4\r" } } expect { 刷题总数 {send "1\r" } } expect { 已经学习完啦!是否继续学习?(Yes/No) {send "yes\r" } } expect { 6、拆盲盒 {send "6\r" } } expect { 已经学习完啦!是否继续学习?(Yes/No) {send "N\r" } }
其中 spawn /home/gostudy/gostudy gostudy 是需要执行的程序
set timeout -1 是永不超时
不想平凡,奈何太懒 T_T