Posted to tcl by kbk at Wed Mar 21 19:41:32 GMT 2018view raw

  1. #!/no_backup/ActiveTcl-8.6/bin/tclsh
  2. package require Expect
  3. # exp_internal 1
  4. spawn /bin/sh
  5. expect {$ }
  6. send "ls -1\n"
  7. expect \r\n
  8. expect {
  9. -re {^([^\r\n]*\.tcl)\r} {
  10. set fname $expect_out(1,string)
  11. puts "Tcl file: $fname"
  12. exp_continue
  13. }
  14. -re {^([^\r\n]*)\r} {
  15. set fname $expect_out(1,string)
  16. puts "Non-Tcl file: $fname"
  17. exp_continue
  18. }
  19. -re {^[^\r\n]*\$ $} {
  20. puts "Got shell prompt again."
  21. }
  22. -re {[^\n]*\n} {
  23. exp_continue
  24. }
  25. timeout {
  26. puts "Timeout before all patterns matched."
  27. }
  28. }
  29. send exit\r\n
  30. expect eof
  31.