Posted to tcl by rical at Tue Jan 17 14:09:05 GMT 2012view raw
- # #
- # Example file:
- match 0: zero
- match 1: one
- match 2: two
- match 3: three
- match 4: four
-
- # #
- # Code
- #!/usr/bin/tclsh
- package require Expect
- log_user 0
-
- spawn "/bin/bash"
- set timeout 1
-
- # #
- # Controll
- puts "Controll"
- send "cat ex.list\n"
- expect {
- -re {match 2: ([[:alpha:]]+)} {puts "2 = $expect_out(1,string)."}
- default {puts "failed"}
- }
- expect *
-
-
- # #
- # Dynamic 1
- set two 2
- set body {
- -re {match $two: ([[:alpha:]]+)} {puts "$two = $expect_out(1,string)."}
- default {puts "failed"}
- }
- puts "Dynamic1"
- send "cat ex.list\n"
- expect $body
- expect *
-
-
- # #
- # Dynamic 2
- lappend body2 "-regexp \{match $two: (\[\[:alpha:]]+)\} \{puts \"$two = $expect_out(1,string).\"\}"
- lappend body2 {default {puts "failed"}}
-
- puts "Dynamic2"
- send "cat ex.list\n"
- expect $body2
-