期待的 - 基于行和列得到屏幕区域变量 [英] Expect - get variable from screen region based on row and column
问题描述
我与SSH会话,用期待一个ERP程序自动进行交互。
,而不是依赖于定期前pression捕获变量在我expect脚本将有可能在从用户接收某个键击捕获屏幕区域,比方说一个场,到一个变量中的code吗?发送服务器的其他一些命令和重发领域?
说,一个订单号码被包含在6,12,6,18个(其中6行和12-18是列)包含我的6位订单号。我想从行获取订单号码6列12至18复制到一个变量。然后允许用户交互的一些(或期望移动到另一个菜单),然后在另一个菜单重新发送的订单号。
所以我想我的问题是:在当前屏幕内容在一个缓冲区? (不是整个会话),你可以提取只是仅会在该行和列的范围内存在屏幕上的某个数据元素?
样伪code:
#!的/ usr / bin中/期望-f
集ENV(TERM)VT100
产卵SSH -Y为user @ domain
#...设置用户名/密码等瓦尔...
#...发送登录到ERP命令
#不会超时
设置超时-1
相互作用 {
-reset $ {CTRLZ杀EXEC -STOP [PID]}
$ {CTRLA
exp_sendmenu_address \\ RY \\ R
}
$ {CTRLO
#...获取订单号码变...
#......有些code我还不明白... exp_sendmenu_exit_sequence \\ R
exp_sendmenu_address \\ R
exp_send $ ordernumvar }
~~
}
没有,你不能抢在特定的行/列的东西从屏幕。但是,想想信息摆在首位是怎么到屏幕上。如果是使用诅咒它输出,导致它出现在该行/列特殊转义序列到stdout一个基于tty的应用。因此,期待这些特定转义序列得到的是在那个位置。
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
}
~~
}
No, you can't grab something off of the screen at a particular row/column. However, think about how the information got to the screen in the first place. If it's a tty-based application using curses it was output to stdout with special escape sequences that caused it to appear at that row/column. So, 'expect' those specific escape sequences to get what is at that position.
这篇关于期待的 - 基于行和列得到屏幕区域变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!