If, instead of using exec
, you launch the subprocess with:
set pipeline [open |[list tclsh a.tcl]]
then the GUI will remain active. However, you'll probably want to read from the pipeline from time to time.
proc line_per_second {pipeline} {
puts [gets $pipeline]
after 1000 line_per_second $pipeline
}
line_per_second $pipeline
When you close $pipeline
, it should shut things down (because the OS pipe gets closed).
Note that for real code, as opposed to code which is just spewing the same line over and over as fast as possible, you can use a readable fileevent
to trigger your call to gets
instead.
proc read_line {pipeline} {
gets $pipeline line
if {[eof $pipeline]} {
close $pipeline
} else {
puts $line
}
}
fileevent $pipeline readable [list read_line $pipeline]
However, with your specific script that might trigger too often and starve the GUI of events a bit. It's only really a problem with very large amounts of output.