You're already waiting for the eof
at the end of your loop, you just need to use wait
and catch
the result:
spawn trueexpect eofcatch wait resultexit [lindex $result 3]
Exits with 0.
spawn falseexpect eofcatch wait resultexit [lindex $result 3]
Exits with 1.