我用期待我的服务器上启动应用程序:背景衍生的过程中期待
!/usr/bin/expect
set timeout -1
spawn "bin/start-all.sh"
expect {
-re "Found MongoDB in" { send "y\r"; exp_continue }
-re "Found Hadoop in" { send "y\r"; exp_continue }
-re "Going to start Hadoop" { interact }
}
我可以在脚本运行时我的服务器上访问在几秒钟内的应用,但只要它结束应用程序变得不可用。
我已经运行预计在调试模式,得到下面的输出接近尾声:
expect: does "vendors area. Do you want to start it? [y/n] y\r\n" (spawn_id exp6) match regular expression "Found MongoDB in"? Gate "Found MongoDB in"? gate=no
"Found Hadoop in "? Gate "Found Hadoop in "? gate=no
"Going to start Hadoop"? Gate "Going to start Hadoop"? gate=no
Going to start Hadoop...
expect: does "vendors area. Do you want to start it? [y/n] y\r\nGoing to start Hadoop...\r\n" (spawn_id exp6) match regular expression "Found MongoDB in"? Gate "Found MongoDB in"? gate=no
"Found Hadoop in "? Gate "Found Hadoop in "? gate=no
"Going to start Hadoop"? Gate "Going to start Hadoop"? gate=yes re=yes
expect: set expect_out(0,string) "Going to start Hadoop"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "vendors area. Do you want to start it? [y/n] y\r\nGoing to start Hadoop"
tty_raw_noecho: was raw = 0 echo = 1
interact: received eof from spawn_id exp6
tty_set: raw = 0, echo = 1
tty_set: raw = 5, echo = 0
我已经尝试使用exit 0
,interact
,exp_continue
,disconnect
,sleep 10
最后的模式下,以及期待eof
,但似乎没有任何工作。我也尝试过运行expect start-all.exp &
,但那也行不通。
当我手动运行bin/start-all.sh时,脚本启动必要的过程,然后退出。但是,预计这些进程似乎会被杀死。我将如何解决这个问题?
有很多的细节,但目前尚不清楚你想要实现什么。 –
这是一个很长的镜头,但你有没有在最后尝试'期待eof'? –
恐怕我不熟悉这个start-all.sh脚本。在Expect的PTY中运行时,它可能会做一些奇怪的事情,导致它过早终止。 – user108471