0

I've a tcl script which runs another tcl script. When the script is called, it creates a log file which is supposed to be updated in the text box(TCL GUI). I tried and failed, below is the code

So I'm planning to run the script in a thread thread1 and access the log file created and update the results in GUI text box using another thread2. If this method is right, suggest how can i modify my existing code to run in threads. I'm open for any method, as I'm a noob in TCL.

#!/usr/bin/wish

set excel_path ""
set types ""

proc receive {chan} {
    .m.consoleText configure -state normal
    .m.consoleText insert end [read $chan]
    .m.consoleText configure -state disabled
    .m.consoleText see end
    if {[eof $chan]} {
        close $chan
    }
}
proc processLogLine {line} {
    # Write this yourself...
    .m.consoleText configure -state normal
    .m.consoleText insert end $line\n
    .m.consoleText configure -state disabled
    .m.consoleText see end
}
proc Run_Button {} {

   cd $folder_path
   set cmd_err [catch {set command [eval exec ../Run/start.tcl]} err_msg]

   if {$cmd_err == 1} { 
   foreach line [split $err_msg "\n"] { 
      processLogLine $line
      } else {
   fconfigure $chan -blocking 0
   fileevent $chan readable "receive $chan"
}
}

frame .m 
frame .m.f -borderwidth 5 -relief sunken -width 1800 -height 900

button .m.selectExcel -text "Choose Excel" -command {

set excel_path [tk_getOpenFile -initialdir "/Run" -defaultextension ".xls" ]

} -width 10
label .m.lab -text "No File choosen"
button .m.myButton -background red -text "Run" -relief ridge -borderwidth 3 -command "Run_Button" -width 10
button .m.closeButton -background red -text "Close" -relief ridge -borderwidth 3 -command exit -width 10
text .m.consoleText -background white -borderwidth 2 -relief sunken -width 180 -height 50 -yscrollcommand {.m.scrl set}
scrollbar .m.scrl -orient vertical -command {.m.consoleText yview} 

entry .m.boardName -relief sunken -width 15 -bd 2 -textvariable ::board

grid .m -column 0 -row 0
grid .m.f -column 0 -row 0 -columnspan 18 -rowspan 36 
grid .m.selectExcel -column 0 -row 0 -columnspan 2
grid .m.lab -column 2 -row 0 -columnspan 16
grid .m.myButton -column 0 -row 1 -columnspan 2
grid .m.closeButton -column 0 -row 35 -columnspan 2
grid .m.boardName -column 0 -row 2 -columnspan 2
grid .m.consoleText -column 2 -row 2 -columnspan 8 -rowspan 30 
grid .m.scrl -column 17 -row 2 -rowspan 32
NMN
  • 372
  • 3
  • 16
  • in Run_Button, where does $chan come from? – glenn jackman May 12 '20 at 14:41
  • 2
    I think this question is exactly what you need: https://stackoverflow.com/q/166231/7552 -- instead of using `exec`, use `open` to create a pipe, then you can read from the pipe and update the text widget. – glenn jackman May 12 '20 at 15:25
  • @glennjackman : Yes, this is what i was exactly looking for. Thanks a lot – NMN May 13 '20 at 05:19

0 Answers0