Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help needed in piping a command output to the TK text widget ..?

Status
Not open for further replies.

prabhuusic

Programmer
May 16, 2011
1
0
0
IN
Hi All,
I have created a text widget in tcl/tk with a vertical scrollbar. I am trying to write a command output from tcl to tk text widget. I would like to scroll the read text before the command get finished.
(i.e asynchronously reading from a pipe). But with the following code the form is getting blocked during the time of writing data to text widget.
Here is the piece of code that I am trying to solve ...

########################################################
set log [text .t -yscrollcommand {.t.yscroll set}]
scrollbar .t.yscroll -command {.t yview} -orient v
pack .t.yscroll -side right -expand yes -fill y -anchor e
pack .t -side left -expand yes -fill both
bind . <Escape> {exit}
wm geometry . 700x400

proc isReadable { f } {
global log
set status [catch { gets $f line } result]
if { $status != 0 } {
puts "error reading $f: $result"
set ::DONE 2
} elseif { $result >= 0 } {
#puts "got: $line"
$log insert end $line\n
$log see end
update idle
} elseif { [eof $f] } {
puts "end of file"
set ::DONE 1
} elseif { [fblocked $f] } {
# Read blocked. Just return
} else {
# Something else
puts "can't happen"
set ::DONE 3
}
}
set fid [open "|ls -lR /"]
fconfigure $fid -blocking false
fileevent $fid readable [list isReadable $fid]
vwait ::DONE
close $fid
########################################################

Can someone guide to resolve the above issue ...!

Thanks in Advance ...
Prabhakar. K
ICL Engineer
SoCtronics Tech. Pvt. Ltd.
Hyderabad-INDIA
 
Not sure exactly what you are looking for but it might be in ththis, extracted from my readfile programme:

# read line repeatedly

proc readline {} {

global fid

gets $fid i
if {[string length $i] != 0} {.listbox insert end "$i\n";.listbox see end}
after 50 readline

}

# start code

# open file and read it in

set fid [open "$file" r ]
while {[eof $fid]==0} {
gets $fid i
.listbox insert end "$i\n"
.listbox see end
}
readline


Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top