To get all three values in the one expect
call, you need a little trickiness.
# Initialize to an empty array
unset myAry
array set myAry {}
# Now let's expect some stuff!
expect {
-re {(\w+)\s+=\s+(-?\d+)} {
# Found it; stuff in an array
set myAry($expect_out(1,string)) $expect_out(2,string)
# TRICKY! Keep waiting if we've not yet got all three values
if {[array size myAry] < 3} {
exp_continue
}
}
}
With that output from the spawned process, that'll set myAry(Quality)
to 100
, myAry(Strength)
to -49
, and myAry(Level)
to -96
. To use both words, use this as your pattern:
{(\w+\s+\w+)\s+=\s+(-?\d+)}
and then you'll probably want to strip the spaces:
set key [string map {{ } {}} $expect_out(1,string)]
set myAry($key) $expect_out(2,string)
# Now that optionally-keep-waiting stanza from above
That can, of course, be a one-liner. I just don't like my lines to be so long usually.