我有下面的expect脚本,它应该将预期值存储到2个变量hex1和十六进制2中。
for {set chan 0} {$chan < 6} {incr chan 1} {
incr $chan_enable_value 1
puts $chan_enable_value\r
send -- "i2c_write -b 0 -r reg -w chan_enable\r"
expect "barebox: /"
send -- "i2c_probe\r"
expect -re "barebox: .* (0x[[:xdigit:]]{2}) (0x[[:xdigit:]]{2})\r\n"
set hex1 $expect_out(1, string)
set hex1 $expect_out(2, string)在运行脚本时,我会得到以下错误
invalid command name ":xdigit:"发布于 2022-07-25 18:26:50
你可能想:
send -- "i2c_probe\r"
# .....^ note the space
# expect uses \r\n line endings: find 2 space-separated hex numbers at the end of line
expect -re "barebox: .* (0x[[:xdigit:]]{2}) (0x[[:xdigit:]]{2})\r\n"
# extract the values captured by the regex parentheses
set hex1 $expect_out(1,string)
set hex2 $expect_out(2,string)
puts [list $hex1 $hex2]大脑屁:方括号是Tcl的命令替换语法,双引号允许内插。
选其中一个
expect -re "barebox: .* (0x\[\[:xdigit:]]{2}) (0x\[\[:xdigit:]]{2})\r\n"
# .........................^.^...................^.^ set regex {barebox: .* (0x[[:xdigit:]]{2}) (0x[[:xdigit:]]{2})}
expect -re "$regex\r\n"我们需要防止将[...]解释为命令替换,但允许解释\r\n,因此有点尴尬。
https://stackoverflow.com/questions/73113276
复制相似问题