rcubefather
rcubefather

Reputation: 1564

How to exit from TCL proc, without exiting process running inside that proc

In the following program, I want to capture the packets in 2nd proc, while ping is running in 1st proc. Now if I execute this program, proc is running ping and exit that. Any idea to to resolve this issue?

My TCL code :

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)
}

Upvotes: 3

Views: 1344

Answers (1)

Googie
Googie

Reputation: 6067

Use "pipe" syntax of open command. Like this: open "|ping 30.1.1.2" r. The only (minor) problem is that the file descriptor returned from the open command needs to be closed by you - it won't close automatically when the process finishes. Here you have more examples: Tcl's wiki

Upvotes: 3

Related Questions