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?
My tests are sql scripts run with psql (postgresql command processor).
Since psql doesn't allow to specify database password as a command line parameter, expect scripts do that.
So, my expect script looks like:
spawn $SPAWN_CMD
expect {
-re "Enter password for new role:" {
send "$PWPROMPT
"
exp_continue
} -re "Enter it again:" {
send "$PWPROMPT
"
exp_continue
} -re "Password(.*)" {
send "$PASSWORD
"
exp_continue
} -re "Password(.*):" {
send "$PASSWORD
"
exp_continue
} eof
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…