Let say, there is a.tcl that contains infinite loop condition, e.g.,
while {1} {
puts $val
}
I want to implement a tk-button, that executes a.tcl file and continues to run and print $val in tk-text window at regular interval of time say every 1sec. Also, when we click on that button again, it should stop running a.tcl
Note : I tried using exec tclsh a.tcl
but it hangs the tk-window because of infinite while loop in a.tcl
If, instead of using
exec
, you launch the subprocess with:then the GUI will remain active. However, you'll probably want to read from the pipeline from time to time.
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 togets
instead.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.