Expect_background和EOF问题

时间:2018-03-07 15:23:21

标签: expect

当我运行一个类似于下面的脚本时,我得到一个错误" expect:spawn id exp4 not open"。

spawn sqlplus instuser/*******  @script

expect "Enter the password for SYSTEM:"
send "********\r"

expect_background {
  "Test pattern 1" {
    set testa 1
  }
  "Test pattern 2" {
    set testb 1
  }
  "Test pattern 3" {
    set testc 1
  }
}

expect eof
# Do more after 

如果我删除了期望的eof,那么期望在脚本完成之前终止。我如何使用expect_background,并在进程终止之前将其读取?我全神贯注地找不到答案。

提前致谢。

1 个答案:

答案 0 :(得分:0)

不确定你在做什么,但你可以使用Tcl的vwait。请参阅以下示例:

[STEP 102] # cat foo.exp
set forever {}

spawn bash -c {for i in {1..5}; do echo foo$i; sleep 1; done}

expect_background {
    something {
        do something
    }
    eof {
        set forever 1
    }
}

vwait forever
wait
[STEP 103] # expect foo.exp
spawn bash -c for i in {1..5}; do echo foo$i; sleep 1; done
foo1
foo2
foo3
foo4
foo5
[STEP 104] #