Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem in retrieving external output

65 views
Skip to first unread message

Santan

unread,
May 18, 2011, 5:20:33 PM5/18/11
to
Hi Friends,
I have an executable who takes few commandline arguments and returns
the results to standard output like a konsole, regularly during it is
running.Example like in just one line "% of completion". I made a tcl
\tk GUI to collect all the necessary information and execute this
external binary via exec.
ex: exec file_to_run $x $y $z
But i am not able to recover its output when it is running back into
my tcl\tk gui. I tried using catch around the exec syntax line but
always getting error. even if i output my external binary output into
a file and read the same file, every 2 seconds from tk, inside a loop,
i am not getting it. My idea is to get the running return value in a
variable and link it to a label textvariable. So that it keeps
changing as the process is running. something like a progress
indicator.
Any help will be useful.

Alexandre Ferrieux

unread,
May 18, 2011, 7:01:37 PM5/18/11
to

Use [open |...] and [fileevent]. See http://wiki.tcl.tk/1860 .

-Alex

Santan

unread,
May 19, 2011, 6:10:01 AM5/19/11
to
On May 19, 1:01 am, Alexandre Ferrieux <alexandre.ferri...@gmail.com>
wrote:

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 ?

Arjen Markus

unread,
May 19, 2011, 7:21:35 AM5/19/11
to
> Can you please help me out ?- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

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
> }

Alexandre Ferrieux

unread,
May 19, 2011, 9:07:01 AM5/19/11
to
On 19 mai, 13:21, Arjen Markus <arjen.markus...@gmail.com> wrote:
>
> The problem with your script is that it may want to read from
> the channel (pipe) after it is closed.

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

Santan

unread,
May 19, 2011, 9:49:33 AM5/19/11
to
Thanks Arjen.
Thanks Alex.

It worked exactly the way i needed!! Very very thanks for helping me
out.
Regards
Santan

0 new messages