我用期待我的服務器上啓動應用程序:背景衍生的過程中期待
!/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