Posted to tcl by rical at Tue Jan 17 14:09:05 GMT 2012view raw

  1. # #
  2. # Example file:
  3. match 0: zero
  4. match 1: one
  5. match 2: two
  6. match 3: three
  7. match 4: four
  8.  
  9. # #
  10. # Code
  11. #!/usr/bin/tclsh
  12. package require Expect
  13. log_user 0
  14.  
  15. spawn "/bin/bash"
  16. set timeout 1
  17.  
  18. # #
  19. # Controll
  20. puts "Controll"
  21. send "cat ex.list\n"
  22. expect {
  23. -re {match 2: ([[:alpha:]]+)} {puts "2 = $expect_out(1,string)."}
  24. default {puts "failed"}
  25. }
  26. expect *
  27.  
  28.  
  29. # #
  30. # Dynamic 1
  31. set two 2
  32. set body {
  33. -re {match $two: ([[:alpha:]]+)} {puts "$two = $expect_out(1,string)."}
  34. default {puts "failed"}
  35. }
  36. puts "Dynamic1"
  37. send "cat ex.list\n"
  38. expect $body
  39. expect *
  40.  
  41.  
  42. # #
  43. # Dynamic 2
  44. lappend body2 "-regexp \{match $two: (\[\[:alpha:]]+)\} \{puts \"$two = $expect_out(1,string).\"\}"
  45. lappend body2 {default {puts "failed"}}
  46.  
  47. puts "Dynamic2"
  48. send "cat ex.list\n"
  49. expect $body2
  50.