Expect_background 和 EOF 问题

Expect_background and EOF Problems

当我 运行 一个类似于下面的脚本时,我得到一个错误 "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 

如果我删除 expect eof,则 expect 在脚本完成之前终止。我如何使用 expect_background,并在进程终止之前读取它?我找遍了,找不到答案。

提前致谢。

不确定你到底在做什么,但你可以使用 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] #