(Tcl/Expect) 退出后清屏

发布于 2024-08-16 17:07:19 字数 918 浏览 5 评论 0原文

我想在退出我的(半)交互式期望脚本后清除屏幕(在本地计算机上)。我可以在脚本中做到这一点吗?这是我尝试过的,但失败了。

#!/usr/bin/expect -f
set env(TERM) vt100
spawn ssh -Y username@domain
set user username
set pass password 
#login sequence
expect "password: "
send "${pass}\r"
sleep .5  
#some menu commands to enter ERP....
#...
#...
set CTRLZ \032
set CTRLC \003
set CTRLA \001
#don't time out
set timeout -1 
        interact {
                -reset $CTRLZ {exec kill -STOP [pid]}
                $CTRLA   {   
                        exp_send "menucmd...\ry\r"
                }   
                $CTRLC   {  

                        #clear the host machine screen???
                        exec clear
                        exit
                }
                ~~  
        } 

在远程端,我不是在 shell 中,而是在 ERP 程序中。如果有必要,我可以退出 shell,然后在远程主机上执行“清除”操作,但我认为远程主机提示符仍会显示在屏幕上。

编辑:更改为在“退出”之前尝试清除(子问题:“execclear”在运行期望脚本的机器上执行,对吗?)

I want to clear the screen (on the local machine) after exiting from my (semi) interactive expect script. Can I do that from within the script? Here's what I tried, that failed.

#!/usr/bin/expect -f
set env(TERM) vt100
spawn ssh -Y username@domain
set user username
set pass password 
#login sequence
expect "password: "
send "${pass}\r"
sleep .5  
#some menu commands to enter ERP....
#...
#...
set CTRLZ \032
set CTRLC \003
set CTRLA \001
#don't time out
set timeout -1 
        interact {
                -reset $CTRLZ {exec kill -STOP [pid]}
                $CTRLA   {   
                        exp_send "menucmd...\ry\r"
                }   
                $CTRLC   {  

                        #clear the host machine screen???
                        exec clear
                        exit
                }
                ~~  
        } 

On the remote side I'm not in a shell but in an ERP program. I could exit to the shell then do a "clear" on the remote host if that's what's necessary, but I think the remote host prompt would still be on the screen.

EDIT: changed to try clear before "exit" (sub-question: "exec clear" is executed on the machine running the expect script right?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玉环 2024-08-23 17:07:19

一旦你[退出],之后的所有事情都不会被执行。您应该在退出之前[execclear]。

如果您使用的是 vt100 兼容终端(大多数 Unix 终端都是),那么您可以尝试直接向终端发送 vt100 命令:

puts \033\[2J

Once you [exit], everything else after is not going to be executed. You should [exec clear] before exiting.

If you're using a vt100 compatible terminal (and most Unix terminals are) then you can try directly sending vt100 commands to the terminal:

puts \033\[2J
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文