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

  1. #!/usr/bin/tclsh
  2. package require Expect
  3. log_user 0
  4.  
  5. spawn "/bin/bash"
  6. set timeout 1
  7.  
  8. # #
  9. # Controll
  10. puts "Controll"
  11. send "cat ex.list\n"
  12. expect {
  13. -re {match 2: ([[:alpha:]]+)} {puts "2 = $expect_out(1,string)."}
  14. default {puts "failed"}
  15. }
  16. expect *
  17.  
  18. # #
  19. # Dynamic
  20. set two 2
  21. lappend body "-regexp"
  22. lappend body "match $two: (\[\[:alpha:]]+)"
  23. lappend body "puts {$two = \$expect_out(1,string).}"
  24. lappend body default {puts "failed"}
  25.  
  26. puts "body: $body"
  27.  
  28. puts "Dynamic2"
  29. send "cat ex.list\n"
  30. expect $body
  31.