📄 tcmd.tcl
字号:
proc execCmdFile {cmdFile} {
global prompt g_dbgFlag g_devip
# enable debug
set g_dbgFlag 1
# login
set spawn_id [login $g_devip "su3" "su3"]
if {$spawn_id == 0} {
errLog "login ipaddr failed"
return 0
}
# open cmdFile
set cmdFd [open $cmdFile r]
set send_human {.1 .3 1 .05 2}
while true {
# get a line
if {![getLine $cmdFd line]} {
dbgLog "测试命令下发结束!"
break
}
# split the line
set ln [split $line ","]
set cmd [string trim [lindex $ln 0]]
set out [string trim [lindex $ln 1]]
if {$cmd == ""} continue
if {$out == ""} {set out $prompt}
# send cmd line
send -h "$cmd\r"
dbgLog "send $cmd"
# expect output
dbgLog "expect $out"
expect {
timeout {
errLog "TIMEOUT: while exec \"$cmd\""
continue
}
-ex "$out" {
continue
}
} ;# end expect
}
# close cmdFile
close $cmdFd
#expect -re (0(.*)3(.*)Work(.*)ALC_H)
#exp_sleep 5
#expect -re "(.*)SU2(config)#"
#send_user "this is buffer_content\n"
set a "$expect_out(0,string)"
send_user "buffer content:$a\n"
set result [regexp (0(.*)3(.*)Work(.*)ALC_H) $expect_out(buffer)]
if {$result==1} {
send_user "匹配成功!\n"
} else {
send_user "匹配失败!\n"
}
send "\r"
expect "$prompt"
send -h "logout\r"
expect eof
}
# if no cmdFile, use default
if {$cmdFile==""} {
set cmdFile "cmdfile.txt"
}
execCmdFile $cmdFile
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -