Posted to tcl by kostix at Sat Feb 02 00:44:33 GMT 2008view raw

  1. grid rowconfigure . 0 -weight 1
  2. grid columnconfigure . 1 -weight 1
  3. grid [text .log] -columnspan 3 -sticky news
  4. grid [label .l -text Command:] -row 1 -column 0 -sticky we
  5. grid [entry .cmd -textvar cmd] -row 1 -column 1 -sticky we
  6. grid [button .exec -text Go! -command go] -row 1 -column 2 -sticky we
  7.  
  8. bind .cmd <Return> go
  9.  
  10. switch -- $tcl_platform(platform) {
  11. unix {
  12. if {[info exists env(SHELL)]} {
  13. set shell $env(SHELL)
  14. } else {
  15. set shell /bin/sh
  16. }
  17. }
  18. windows {
  19. if {[info exists env(COMSPEC)]} {
  20. set shell $env(COMSPEC)
  21. } else {
  22. set cmd.exe
  23. }
  24. }
  25. default {
  26. return -code error "Freaky platform"
  27. }
  28. }
  29.  
  30. set fd [open [list | $shell] w+]
  31. fconfigure $fd -blocking no -buffering line
  32. fileevent $fd readable get
  33.  
  34. proc get {} {
  35. variable fd
  36.  
  37. if {[gets $fd line] < 0} {
  38. close $fd
  39. .log insert end "SHELL quit"
  40. } else {
  41. .log insert end $line
  42. }
  43. }
  44.  
  45. proc go {} {
  46. variable cmd
  47. variable fd
  48.  
  49. puts $fd $cmd
  50. }
  51.  
  52. vwait forever