Nomen Nescio <
nob...@dizum.com> writes:
> If I call a long running non-Tcl script with exec or catch exec how can I
> present a progress bar? I have no idea how long the script will execute, I
> just have to wait until its done. The examples I found on the Tcl wiki
> looked very involved and didn't show how to test them. I'm sure this is
> shown somewhere but I'm just finding my way around all the Tcl materials
> now. Thanks for your suggestions.
AFAIK exec will wait until the external script is done, so no chance to
show a "moving progress bar" during the process.
Try a combination of [open] (and set the file descriptor you get to
"non-blocking" and [fileevent] to get output from the command, roughly
like so:
------
set fh [open "$command 2>@stdout"]
fconfigure $fh -blocking none ;# optionally -buffering none
fileevent $fh readable recv
proc recv {chan} {
$progress configure -value [expr [$progress cget -value] + 10]
# or whatever is appropriate
}
# Since you don't know how much is 100 percent, you'll have to make do
# with a "cycling" progress bar:
set progress [ttk::progressbar .pro -mode indeterminate]
------
Warning: hopelessly untested code! This assumes that the process
produces some output to trigger our progress thingy. You'll have to add
some code to catch the end of things (the channel gets presumably
closed). Some error handling won't hurt either.
See
<
http://wiki.tcl.tk/1039>
<
http://wiki.tcl.tk/12704>
<
http://wiki.tcl.tk/9691>
for some inspiration.
Regards
-- tomás