views:

286

answers:

1

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

+3  A: 

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
slebetman
I switched the order of those two lines to no effect...
jjclarkson
What platform are you running on?
slebetman
The local system (running the expect script) is ubuntu linux. The host the script is logging into is running SCO Unix.
jjclarkson
This worked perfectly. However I had an error until I escaped the single bracket. puts -nonewline \033\[2J flush stdoutAlso in my case I preferred the effect of the newline so I dropped "-nonewline".
jjclarkson
Edited to fix bugs.
slebetman