如何将睡眠命令放入 tcl 脚本中?
How to put sleep command in a tcl script?
我正在尝试在 tcl 脚本中放置一个睡眠命令,等待 10 秒后再发送断开连接命令:
#!/usr/bin/expect -f
set n 0
if { $argc != 1 } {
puts "The script requires the number of bot."
puts "Please try again."
exit 1
} else {
set n [lindex $argv 0]
}
# Spawn Python and await prompt
spawn mono --debug pCampBot.exe -loginuri http://127.0.0.1:9000 -s home -n $n -firstname test -lastname bot_ -password 123 -b p
expect "pCampbot#"
# Send Python statement and await prompt
send "conn\n"
expect "pCampbot#"
sleep 10
send "disconn\n"
expect "pCampbot#"
# Pass control to user so he can interact with Python
interact
问题是 sleep 命令就像是在 spawn 命令之后执行的,也就是说它等待 10 秒,然后依次发送 "conn" 和 "disconn" 命令。
我不知道为什么会这样,我也不知道如何解决这个问题。
Tcl 为此使用 after
命令,前提是您给它一个参数,该参数是 毫秒 的整数。要睡 10 秒,您需要:
after 10000
我正在尝试在 tcl 脚本中放置一个睡眠命令,等待 10 秒后再发送断开连接命令:
#!/usr/bin/expect -f
set n 0
if { $argc != 1 } {
puts "The script requires the number of bot."
puts "Please try again."
exit 1
} else {
set n [lindex $argv 0]
}
# Spawn Python and await prompt
spawn mono --debug pCampBot.exe -loginuri http://127.0.0.1:9000 -s home -n $n -firstname test -lastname bot_ -password 123 -b p
expect "pCampbot#"
# Send Python statement and await prompt
send "conn\n"
expect "pCampbot#"
sleep 10
send "disconn\n"
expect "pCampbot#"
# Pass control to user so he can interact with Python
interact
问题是 sleep 命令就像是在 spawn 命令之后执行的,也就是说它等待 10 秒,然后依次发送 "conn" 和 "disconn" 命令。
我不知道为什么会这样,我也不知道如何解决这个问题。
Tcl 为此使用 after
命令,前提是您给它一个参数,该参数是 毫秒 的整数。要睡 10 秒,您需要:
after 10000