gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 00:16:48 26 4
gpt4 key购买 nike

我使用 expect 来运行测试脚本。测试通过退出代码返回成功/失败。但期望返回等效的退出代码。如何让expect返回正确的退出状态?

我的测试是使用 psql(postgresql 命令处理器)运行的 sql 脚本。由于 psql 不允许将数据库密码指定为命令行参数,期待脚本这样做。

因此,我的期望脚本如下所示:

spawn $SPAWN_CMD
expect {
-re "Enter password for new role:" {
send "$PWPROMPT\n"
exp_continue
} -re "Enter it again:" {
send "$PWPROMPT\n"
exp_continue
} -re "Password(.*)" {
send "$PASSWORD\n"
exp_continue
} -re "Password(.*):" {
send "$PASSWORD\n"
exp_continue
} eof
}

最佳答案

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

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

以 0 退出。

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

以 1 退出。

关于linux - 如何在 Expect 脚本中返回生成的进程退出代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3299502/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com