且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Expect 脚本中返回生成的进程退出代码?

更新时间:2023-02-07 14:32:36

你已经在等待循环结束时的 eof,你只需要使用 waitcatch 结果:

You're already waiting for the eof at the end of your loop, you just need to use wait and catch the result:

spawn true
expect eof
catch wait result
exit [lindex $result 3]

以 0 退出.

spawn false
expect eof
catch wait result
exit [lindex $result 3]

以 1 退出.