Thanks Alex,
I tried using open and fileevent. The code now looks like this ...
set pro79 [open "| ./my_ext_prog $f1 $f2 $f3 $f4 " "r"]
fconfigure $pro79 -buffering line
fileevent $pro79 readable [list getdata $pro79]
proc getdata {chan} {
if {[eof $chan]} {
close $chan
}
gets $chan nbrtr
.lab1 config -text " $nbrtr completed "
}
But the problem is still there. In the start it shows "0 completed"
for the label but then nothing happens and it crashes showing the
error "can not find channel named file6" while executing "gets $chan
nbrtr" from the "getdata file6"
I don't have anywhere file6 in my code. I am not able to understand
what is going wrong, where ?
Can you please help me out ?
Hi Santan,
file6 is the value of pro79.
The problem with your script is that it may want to read from
the channel (pipe) after it is closed.
Try:
set pro79 [open "| ./my_ext_prog $f1 $f2 $f3 $f4 " "r"]
fconfigure $pro79 -buffering line
fileevent $pro79 readable [list getdata $pro79]
proc getdata {chan} {
if { ![eof $chan]} {
gets $chan nbrtr
.lab1 config -text " $nbrtr completed "
} else {
close $chan
}
}
Regards,
Arjen
> }
Yes :)
> fconfigure $pro79 -buffering line
Useless. Line-buffering is an output feature, here the channel is only
input.
> proc getdata {chan} {
> if { ![eof $chan]} {
> gets $chan nbrtr
> .lab1 config -text " $nbrtr completed "
> } else {
> close $chan
> }
A slightly more elegant idiom is
proc getdata chan {
if {[gets $chan nbrtr]<0} {
close $chan
return
}
.lab1 config -text " $nbrtr completed "
}
-Alex
It worked exactly the way i needed!! Very very thanks for helping me
out.
Regards
Santan