When you do gets stdin
, Tcl (normally) waits until it receives a line from standard input. If you want to keep a GUI (or other background-processing system) going but still wait for a line, you need a slightly different approach.
proc getStdinLine {} {
set ::user_input [gets stdin]
}
fileevent stdin readable getStdinLine
vwait ::user_input
# Unregister the callback
fileevent stdin readable {}
BEWARE! This code can have problems with reentrancy; if your script manages to get back to the same point while it is waiting, it can very easily get itself in a real mess. This is because vwait
keeps a record of what is being waited for on the C stack; this remains true even in Tcl 8.6 (though that has coroutines which you can use to create a workaround, if ModelSim is cooperative enough).