[英]How to check success or failure of a command that is within an expect block
I have a bash code which uses expect in between to read from terminal through spawn. 我有一个bash代码,使用之间的期望从终端通过生成读取。 The code is somewhat as shown:
代码如下所示:
expect <{cat <<'EOD'
spawn command_whose_success_or_failure_i_want_to_know
interact
EOD
)
The problem is to find the success or failure of "command_whose_success_or_failure_i_want_to_know" within expect block. 问题是在Expect块中查找“ command_whose_success_or_failure_i_want_to_know”的成功或失败。
Right now when I am doing : 现在,当我在做:
if [ $? -eq 0 ]; then
blah
It is actually checking for expect success and not the inside command which I want to check for. 它实际上是在检查预期成功,而不是我要检查的内部命令。 How can I do that here?
我该怎么办? Thanks
谢谢
You'll do this (untested): 您将执行此操作(未测试):
expect <<'END_EXPECT'
# if your command takes > 10 seconds to complete, uncomment the next line:
# set timeout $some_number_of_seconds_or_negative_one
spawn command_whose_success_or_failure_i_want_to_know
expect eof
set result [wait]
if {[lindex $result 2] == 0} {
exit [lindex $result 3] ;# exit expect with the command's exit status
} else {
error "an operating system error occurred, errno=[lindex $result 3]"
}
END_EXPECT
exit_status=$?
echo "the command exited with: $exit_status"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.