问题描述
我不知道如何使用Expect发送箭头键,因此我为所有箭头键生成了autoexpect脚本,并发现autoexpect为右箭头键生成了此字符:
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"
我在自定义脚本中使用了相同的send命令,但出现以下错误:
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.
推荐答案
"^[\[C"
是Tcl
中的无效字符串. ^[
应该是\033
的ESC
字符.所以试试这个:
"^[\[C"
is an invalid string in Tcl
. ^[
should be the ESC
char which is \033
. So try this:
send "\033\[C"
已更新:
为当前终端(如在$TERM
中)获取正确的右箭头键的最安全方法是使用tput
:
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] #
要了解cuf1
的含义,请搜索terminfo
的手册页. :)
To know what cuf1
means, search terminfo
's man page. :)
这篇关于期望脚本箭头键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!