gpt4 book ai didi

tcl - 如何退出 TCL proc,而不退出在该 proc 内运行的进程

转载 作者:行者123 更新时间:2023-12-04 23:01:39 28 4
gpt4 key购买 nike

在下面的程序中,我想在第 2 个过程中捕获数据包,而 ping 在第 1 个过程中运行。现在,如果我执行这个程序,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)
}

最佳答案

使用open 命令的“管道”语法。像这样:打开“|ping 30.1.1.2”r。唯一的(小)问题是从 open 命令返回的文件描述符需要由您关闭 - 它不会在进程完成时自动关闭。这里有更多示例:Tcl's wiki

关于tcl - 如何退出 TCL proc,而不退出在该 proc 内运行的进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23516900/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com