문제

나는 기대 스크립트를 작동 시키려고 노력하고 있으며 -re 플래그 (정규 표현 구문 분석을 호출하기 위해)를 사용하면 '타임 아웃'키워드가 더 이상 작동하지 않는 것 같습니다. 다음 스크립트가 실행되면 '1 단계에서 시간을 초과'한 다음 'STEP 2 STEP 2'메시지를받은 다음 시간이 걸리지 만 '2 단계에서 시간 타임 아웃'을 인쇄하지 않습니다. 새 프롬프트가 나타납니다.

아이디어?

#!/usr/bin/expect --

spawn $env(SHELL)
match_max 100000

set timeout 2

send "echo This will print timed out\r"
expect  {
    timeout { puts "timed out at step 1"  }
    "foo " { puts "it said foo at step 1"}
}

puts "Starting test two\r"

send "echo This will not print timed out\r"
expect  -re {
    timeout { puts "timed out at step 2" ; exit }
    "foo " { puts "it said foo at step 2"}
}
도움이 되었습니까?

해결책

Figured it out:

expect  {
    timeout { puts "timed out at step 2" ; exit }
    -re "foo " { puts "it said foo at step 2"}
}

다른 팁

Yes, the "-re" flag as it appears in your question will apply to every pattern in the expect command. So the "timeout" pattern becomes "-re timeout", losing its specialness.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top