(Tcl/Expect) 退出后清屏
我想在退出我的(半)交互式期望脚本后清除屏幕(在本地计算机上)。我可以在脚本中做到这一点吗?这是我尝试过的,但失败了。
#!/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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一旦你[退出],之后的所有事情都不会被执行。您应该在退出之前[execclear]。
如果您使用的是 vt100 兼容终端(大多数 Unix 终端都是),那么您可以尝试直接向终端发送 vt100 命令:
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: