本文介绍了使用“期望"滚动浏览并接受许可协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一堆Mac,它们刚刚更新了Xcode,并且需要接受EULA协议.我正在尝试通过脚本来做到这一点.
I've got a bunch of Macs that have just updated Xcode and need to have the EULA agreement accepted. I'm trying to do this through a script.
#!/usr/bin/expect
set timeout 15
spawn sudo xcodebuild -license
expect {
"*License.rtf'\n" { # Press Enter to view agreement
send "\r"
}
timeout {
send_user "\nFailed\n";
exit 1
}
}
expect {
"Software License Agreements Press 'space' for more, or 'q' for quit" {
send_user " ";
exp_continue;
}
"By typing 'agree' you are agreeing" {
send_user "agree\r"
}
timeout {
send_user "\nTimeout 2\n";
exit 1
}
}
但是,它永远不会超过第一个期望值(也就是说,它永远不会为"Enter"发送"\ r".这是输出:
However, it never gets passed the first expect (that is, it never sends the "\r" for 'Enter'.Here is the output:
$ ./test.sh
spawn sudo xcodebuild -license
You have not agreed to the Xcode license agreements. You must agree to both license agreements below in order to use Xcode.
Hit the Enter key to view the license agreements at '/Applications/Xcode.app/Contents/Resources/English.lproj/License.rtf'
Failed
更新的脚本如下,现在达到第二个期望值的超时时间:
Updated script as follows, now hits timeout at the second expect:
#!/usr/bin/expect
set timeout 15
spawn sudo xcodebuild -license
expect {
"*License.rtf" {
send "\r"
}
timeout {
send_user "\nFailed\n";
exit 1
}
}
expect {
"By typing 'agree' you are agreeing" {
send "agree\r"
}
"*Press 'space' for more, or 'q' for quit" {
send " ";
exp_continue;
}
timeout {
send_user "\nTimeout 2\n";
exit 1
}
}
推荐答案
使用 @Glenn Jackman 中的信息,我能够解决这个问题.这是我的解决方案,嵌入在bash脚本中
Using the information from @Glenn Jackman, I was able to solve this. Here is my solution, embedded in a bash script
/usr/bin/expect<<EOF
spawn sudo xcodebuild -license
expect {
"*License.rtf" {
send "\r";
}
timeout {
send_user "\nExpect failed first expect\n";
exit 1;
}
}
expect {
"*By typing 'agree' you are agreeing" {
send "agree\r";
send_error "\nUser agreed to EULA\n";
}
"*Press 'space' for more, or 'q' to quit*" {
send "q";
exp_continue;
}
timeout {
send_error "\nExpect failed second expect\n";
exit 1;
}
}
EOF
这篇关于使用“期望"滚动浏览并接受许可协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!