【发布时间】:2014-06-24 09:03:18
【问题描述】:
在下面的程序中,我想在 2nd proc 中捕获数据包,而 ping 在 1st proc 中运行。现在如果我执行这个程序,proc 正在运行 ping 并退出它。有解决此问题的想法吗?
我的 TCL 代码:
proc connect {} {
global spawn_id
spawn telnet $1.1.1.1
expect "*ogin:"
send "admin\r"
expect "*word:"
send "test\r"
expect "*>"
send "ping 30.1.1.2\r" ; # Ping here
expect "*#"
}
proc pktcap {} {
spawn telnet $2.2.2.2
expect "*ogin:"
send "admin\r"
expect "*word:"
send "test\r"
expect "*>"
send "enable\r"
expect "*#"
send "service pktcap on interface vlan 2\r" ; # capture here, see the ICMP packets
expect "*#"
set data $expect_out(buffer)
}
【问题讨论】:
-
完全未经测试:尝试在后台启动 ping:
send "ping 30.1.1.2 & \r" -
期望的异步操作?
expect_background可能是相关的,但代码不能像那样直线编写。我不知道 expect 和 8.6 的协程是否可以很好地协同工作……但如果不是,我不会感到惊讶。 -
嗨,格伦,感谢您的评论。是的。如果它的 linux 机器发送“ping 30.1.1.2 & \r”可以工作。我用的是cisco路由器,不支持&功能。
-
您好,Donal,非常感谢您的评论。没有 proc,expect_background 可以正常工作。