Expect - get a variable from the screen area based on row and column

I automatically interact with an SSH session and an ERP program using Expect.

Instead of relying on a regular expression to capture a variable in my expectation of a script, would it be possible after receiving a certain keystroke from a user to capture an area of ​​the screen, say a single field, into a variable in the code? Send the server to other commands and resubmit this field?

Say that the order number is contained in 6, 12, 6, 18 (where 6 is the row and 12-18 are the columns) containing my 6-digit serial number. I want this order number from the columns of the 6th row from 12 to 18 to copy this value into a variable. Then allow the user to interact more (or expect to switch to another menu), and then resend the order number in another menu.

So, I think, my question is: current screen contents in one buffer? (not the whole session) Can you extract only a specific data item that will exist only in this range of rows and columns on the screen?

Pseudo-code example:

#!/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

                }
                ~~
        }
+3
source share
3 answers

, - /. , . tty, curses, stdout escape-, /. , "" escape-, , .

0

term_expect, Expect, . , , . ActiveTcl demos/Expect/term_expect.

+1

ERP, , exp_internal .

exp_internal -f file 0

: ( 076338)

spawn id exp0 sent <0>^M
spawn id exp6 sent <0>^M
spawn id exp0 sent <7>^M
spawn id exp6 sent <7>^M
spawn id exp0 sent <6>^M
spawn id exp6 sent <6>^M
spawn id exp0 sent <3>^M
spawn id exp6 sent <3>^M
spawn id exp0 sent <3>^M
spawn id exp6 sent <3>^M
spawn id exp0 sent <8>^M
spawn id exp6 sent <8>^M
spawn id exp0 sent <\r>^M
spawn id exp6 sent <\r\n\u001b[1;14H>^M

, , . :

-nobuffer -re {^([a-zA-Z0-9]{1})?[0-9]{5}$} {
    set ordernumber $interact_out(0,string)
}

:

^([a-zA-Z0-9]{1})?[0-9]{5}

, :

\r\n\u001b[1;14H

, $ordernumber, - .

0

Source: https://habr.com/ru/post/1727033/


All Articles