How to return spawned process exit code in Expect script?

后端 未结 1 1141
被撕碎了的回忆
被撕碎了的回忆 2020-12-15 17:46

I use expect for running test scripts. Tests return success/failure through exit code. But expect return equivalent exit code. How to make expect return proper exit status?<

相关标签:
1条回答
  • 2020-12-15 18:40

    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]
    

    Exits with 0.

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

    Exits with 1.

    0 讨论(0)
提交回复
热议问题