我试图同时产生 2 个进程,同时期望和发送命令。
spawn telnet $IP1 $Cons1
set id1 $spawn_id
set spawns(1) $spawn_id
set logfile($spawn_id) [open "./$IP1-$Cons1-logs.txt" a]
spawn telnet $IP2 $Cons2
set id2 $spawn_id
set spawns(2) $spawn_id
set logfile($spawn_id) [open "./$IP2-$Cons2-logs.txt" a]
trace add variable expect_out(buffer) write log_by_trace
expect -i spawns(1) "]"
expect -i spawns(2) "]"
send -i spawns(1) "\r\r\r"
send -i spawns(2) "\r\r\r"
expect -i spawns(1) ">"
expect -i spawns(2) ">"
send -i spawns(1) "sometext\r"
expect -i spawns(1) {
#Here, match itself is not happening. Does it has anything to do with '-i spawn(1)'
-re {This\s+is\s+sample(\d).*info\s+(\w{3})} {}
timeout {puts "timeout happened"}
}
#Here, i am getting no such element for the below 2 statements and
#there is no such output in expect_out(buffer)
puts $expect_out(buffer)
set x $expect_out(1,string)
set y $expect_out(2,string)
puts $x;
puts $y
send -i spawns(2) "sometext\r"
expect -i spawns(2) {
-re {This\s+is\s+sample(\d).*info\s+(\w{3})} {}
timeout {puts "timeout happened"}
}
set slot $expect_out(1,string)
set card_state $expect_out(2,string)
set x $expect_out(1,string)
set y $expect_out(2,string)
puts $x;
puts $y
我无法获得正则表达式的匹配项,并且其中没有内容
put $expect_out(buffer)
我匹配的数据如下,
This is sample-2(1), info ACT
我试图从这场比赛中获得价值 '2' 和 'ACT'。
expect
我是否必须像我为and所做的那样针对特定的生成过程指定它send
?如果是,该怎么做?
谢谢