且构网

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

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

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

在循环结束时您已经在等待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退出.