I was testing a expect script and found two different behaviors when using set timeout vs. expect -timeout. Here is a simple example
response.sh:
#!/usr/bin/bash
sleep 2
echo hello
test1.sh:
#!/usr/bin/expect
spawn ./response.sh
set timeout -1
expect {
timeout {
send_user "timeout\n"
} "hello" {
send_user "received hello\n"
}
}
Output (works as expected):
spawn ./response.sh
hello
received hello
however when I use the -timeout flag in expect I never get a response back no matter what value I use for timeout:
#!/usr/bin/expect
spawn ./response.sh
expect -timeout 1 {
timeout {
send_user "timeout\n"
} "hello" {
send_user "received hello\n"
}
}
Output:
spawn ./response.sh
I am expecting timeout to be also printed in stdout. Am I missing anything?