I'm auto-interacting with an SSH session and an ERP program using Expect.
Rather than relying on a regular expression to capture a variable in my expect script would it be possible upon receiving a certain keystroke from a user to capture a screen region, say one field, into a variable in the code? Send the server some other commands and resend the field?
Say an order number is contained at 6, 12, 6, 18 (where 6 is the row and 12-18 are the columns) containing my 6 digit order number. I want to get that order number from row 6 columns 12 to 18 copy that into a variable. Then allow the user to interact some more (or expect a move into another menu), then re-send the order number in another menu.
So I guess my question is: Are the current screen's contents in one buffer? (not the whole session) Can you extract just a certain data element that would only exist at that row and column range on the screen?
Sample pseudocode:
#!/usr/bin/expect -f
set env(TERM) vt100
spawn ssh -Y user@domain
#... set user/pass and other vars...
#... send commands to log into ERP
#don't time out
set timeout -1
interact {
-reset $CTRLZ {exec kill -STOP [pid]}
$CTRLA {
exp_send "menu_address\ry\r"
}
$CTRLO {
#...acquire order number variable...
#...some code I don't understand yet...
exp_send "menu_exit_sequence\r"
exp_send "menu_address\r"
exp_send $ordernumvar
}
~~
}