提问人:Bartlomiej Zuranski 提问时间:9/28/2022 最后编辑:Dennis WilliamsonBartlomiej Zuranski 更新时间:10/4/2022 访问量:57
期望与外部脚本交互调用在发送时打印乱码字符追加
expect Interact call with external script prints gibberish chars append on send
问:
我从期望脚本生成bash进程,以在远程服务器上运行外部脚本文件。 当它运行时,它要求 1 个字符输入和 read
外部 script.sh: read -n1 -p “运行函数?[y,n]“$'\n' pulltar 箱 .... 电子案例
期望部分是:
...
expect -exact "RunFunction?"
expect "\n"
expect_user -re "(.*)\n"
set pulltar $expect_out(1,string)
send_user $pulltar < this test prints single char as given y Or n
send "$pulltar\r" < this prints "^[[6;1Rn" and in consequence does not work
interact -o -nobuffer -re "DONE" return
脚本运行时的示例输出
RunFunction? [y,n]
n < send_user output
^[[6;1Rn < send command output, this triggers my exception
如果我删除发送命令,它仍然可以工作,但需要提供两次输入,第一次是在“expect_user”上,然后再次。有什么建议吗?
答:
0赞
Bartlomiej Zuranski
10/4/2022
#1
我已经修好了。我在 expect 中创建了 var:
set answer "(y|n)"
set answer [string trim $answer]
我是这样通过我的论点的:
expect -exact "RunFunction?"
expect_user -re $answer
set pulltar $expect_out(1,string)
send "$pulltar\r" interact -o -nobuffer -re "DONE" return
评论