Shell 如何使用请求和睡眠进行用户期望和发送
当密码出现时 我想使用expect在5s后自动输入请求的结果 MacosShellExpectShell 如何使用请求和睡眠进行用户期望和发送,shell,expect,Shell,Expect,当密码出现时 我想使用expect在5s后自动输入请求的结果 MacosShellExpect expect << ! set timeout -1 spawn bundle exec fastlane fastlane-credentials add --username sakura expect "*Password*" sleep 5 send `curl http://localhost/a.txt` interact ! expect在tcl语言中,在每次第一次发送命
expect << !
set timeout -1
spawn bundle exec fastlane fastlane-credentials add --username sakura
expect "*Password*"
sleep 5
send `curl http://localhost/a.txt`
interact
!
expect在tcl语言中,在每次第一次发送命令解释时,睡眠将无法与进程交互。将睡眠置于expect应该工作之前,但您需要将密码保存在临时文件中作为存储。更多详细信息,示例代码如下所示:
#!/usr/bin/expect
set timeout -1
spawn bundle exec fastlane fastlane-credentials add --username sakura
sleep 5
send_user "[exec curl -s http://localhost/a.txt -o /tmp/_passwd.txt]"
set fp [open "/tmp/_passwd.txt" r]
set passwd [read $fp]
close $fp
send_user "[exec rm -f /tmp/tmp/_passwd.txt]"
puts $passwd
expect "*Password*"
send '$passwd\r'
interact
不要使用backticks:shell正在劫持它们,并在expect启动之前执行curl。使用纯引号:send“curlhttp://localhost/a.txt“
看一看,您可以使用哪个命令只使用shell代码编写Expect脚本。但是,如果我使用“It’s just a string,I want to a result of the request