Expect script arrow keys

谁说胖子不能爱 提交于 2019-12-13 03:05:50

问题


I didn't know that how to send arrow keys using expect, hence I generated autoexpect script for all the arrow keys and found out that autoexpect generates this character for right arrow key:

send -- "^[\[C"

I used the same send command in my custom script and I'm getting a following error:

while executing
"send -- "^[\[C"
expect eof
"
    (file "script_auto.exp" line 38)

What exactly shall I do to send the right arrow key. Any help would be appreciated.


回答1:


"^[\[C" is an invalid string in Tcl. ^[ should be the ESC char which is \033. So try this:

send "\033\[C"

UPDATED:

The safest way to get the correct RIGHT ARROW key for current terminal (as in $TERM) is to use tput:

[bash] # v=$(tput cuf1)
[bash] # printf '%q\n' "$v"
$'\E[C'
[bash] #

To know what cuf1 means, search terminfo's man page. :)



来源:https://stackoverflow.com/questions/27496136/expect-script-arrow-keys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!