How to return spawned process exit code in Expect script? How to return spawned process exit code in Expect script? linux linux

How to return spawned process exit code in Expect script?


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.