(Tcl/Expect) clear screen after exit

折月煮酒 提交于 2019-12-11 03:26:08

问题


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?)


回答1:


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


来源:https://stackoverflow.com/questions/1987302/tcl-expect-clear-screen-after-exit

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