使expect脚本传回返回值
使expect脚本传回返回值
1、使用expect示例:
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
}
2、返回值
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.
原文
http://stackoverflow.com/questions/3299502/how-to-return-spawned-process-exit-code-in-expect-script