Tommaso Sgarbanti
Tommaso Sgarbanti

Reputation: 33

expect script error interact: spawn id exp4 not open

I have a script that it work well as i expect but at the end, when it terminates, produces this error:

interact: spawn id exp4 not open
    while executing
"interact"
    (file "./pippo.sh" line 8)

The code is:

#!/usr/bin/expect

# Spawn Python and await prompt
spawn mono OpenSim.exe

expect_background {
    "Now recording all stats to file every {0}ms" { sleep 10 ; send "stats record stop\n" ; expect "Stopped recording stats to file." {sleep 5 ; send "quit\n"} }
}

interact

Upvotes: 0

Views: 1077

Answers (1)

meuh
meuh

Reputation: 12255

This is normal if, when your expect_background sends quit\n, the spawned process exits. This will close the file descriptor (spawn id) connecting expect to the process, and so interact will fail when it tries to continue reading (or writing) the process.

You can suppress the error by adding a line to your background command that detects end-of-file and exits when it does:

expect_background {
  "Now recording all stats to file every {0}ms" \
  { sleep 10 ; send "stats record stop\n" ; \
    expect "Stopped recording stats to file." \
    { sleep 5 ; send "quit\n"; \
      expect eof exit } } }

Upvotes: 1

Related Questions