如何在“expect script”中启动shell脚本?

时间:2014-05-14 18:10:42

标签: expect

在这个期望脚本中没有连接ssh服务器,我只想在本地执行“.sh”文件,这可能吗?

例如:

#!/bin/expect

command "xxx.sh" # a command which starts a certain shell script

此外,是否可以在期望脚本中执行expect脚本?

例如:

#!/bin/expect

command "xxx.exp" # a command which starts a certain expect script

任何帮助?

2 个答案:

答案 0 :(得分:3)

Expect中运行shell命令的命令是spawn

#!/bin/expect
spawn command arg1 arg2 ...

command可以是任何程序 - 二进制可执行文件,shell脚本,另一个期望脚本等。所以你可以这样做:

spawn xxx.sh

或:

spawn xxx.exp

答案 1 :(得分:3)

如果您需要与此脚本进行互动,请使用spawn xxx.sh

如果您只需要运行它并捕获输出,请使用set output [exec xxx.sh]

Expect是Tcl语言的扩展,因此您可以顺利通过Tcl tutorial

相关问题