开发者

(Tcl/Expect) clear screen after exit

开发者 https://www.devze.com 2022-12-15 09: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.

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
开发者_StackOverflow社区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?)


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
0

精彩评论

暂无评论...
验证码 换一张
取 消