期望脚本箭头键 [英] Expect script arrow keys

查看:281
本文介绍了期望脚本箭头键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何使用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中的无效字符串. ^[应该是\033ESC字符.所以试试这个:

"^[\[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. :)

这篇关于期望脚本箭头键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆