How to start a shell script within “expect script”?

牧云@^-^@ 提交于 2020-01-24 09:03:40

问题


In this expect script there will be no ssh server connected, I just want to execute a ".sh" file locally, is that possible?

For instance:

#!/bin/expect

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

Also, is it possible to execute a expect script within a expect script?

For instance:

#!/bin/expect

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

Any help?


回答1:


The command in Expect to run a shell command is spawn.

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

command can be any program -- a binary executable, a shell script, another expect script, etc. So you can do:

spawn xxx.sh

or:

spawn xxx.exp



回答2:


If you need to interact with this script, use spawn xxx.sh

If you just need to run it and capture the output, use set output [exec xxx.sh]

Expect is an extension of the Tcl language, so you would be well served to go through the Tcl tutorial.



来源:https://stackoverflow.com/questions/23662020/how-to-start-a-shell-script-within-expect-script

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