expectスクリプトの '-re'フラグでタイムアウトが機能しない

StackOverflow https://stackoverflow.com/questions/136554

  •  02-07-2019
  •  | 
  •  

質問

期待どおりのスクリプトを機能させようとしていますが、-reフラグを使用して(正規表現解析を呼び出す)、「timeout」キーワードが機能しなくなったようです。次のスクリプトを実行すると、「ステップ1でタイムアウト」、「ステップ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"}
}

他のヒント

はい、&quot; -re&quot;質問に表示されるフラグは、expectコマンドのすべてのパターンに適用されます。したがって、「タイムアウト」はパターンは「-re timeout」になり、特殊性が失われます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top