雖然已經在網路上找到tkcon / fconfigure / fileevent的方案,但是執行時總是
不能依照想法顯示,這兩天終於看到解法,當然要把程式的重點記錄下來
(1)設置tkcon
set ::f [frame .lgf]
namespace eval :: [list source $path/tkcon26.tcl]
package require tkcon 2.6
set wpath "$::f.fb"
set tkcon [tkcon::AtSource $wpath]
pack $::f.fb -expand 1 -fill both
grid $::f -row 7 -column 0 -columnspan 9 -sticky news
(2) 輸出至tkcon
proc ::readMe {chan} {if {[gets $chan line] < 0} {
if {[eof $chan]} {
close $chan
set ::done ok
}
} else {
::tkcon::EvalSlave puts $line
flush $chan
}
}
set cmd1 [open "| command_name" r+]
fconfigure $cmd1 -blocking 0
fileevent $cmd1 readable "readMe $cmd1"
(4) log輸出結束後再繼續執行下一步
vwait $::done
沒有留言:
張貼留言