当expect脚本中有多条"spawn"语句时,只完整执行最后一条spawn语句

When there are multiple "spawn" statements in the expect script, only the last spawn statement is executed fully

从 expect 脚本,我正在调用另外两个 shell 脚本。但似乎只有第二个 shell 脚本可以正确执行。因为屏幕上看不到第一个 shell 脚本的输出语句。 这是我期望的脚本:

#!/usr/bin/expect
spawn /bin/bash test1.sh
spawn /bin/bash test2.sh
interact

为什么会这样?解决方法是什么?

您必须等待第一个 spawned 进程完成:

spawn /bin/bash test1.sh
expect eof

spawn /bin/bash test2.sh
interact