Reputation: 125
It's not the first time that I'm using TCL to capture output from a program executed by TCL. I did it several times.
the simple way is to store a result of the exec command in a tcl variable but it is not the good way if the ouput of the program is quite long or if the program wait a lot of time between each display.
so I use 2 other methods using "open" command. But none of them works with questa-lint windows executable (it is working with linux executable). :
method 1 (open without pipe) :
set appli [open "|toto.exe 2>@ $logfile" r]
fconfigure $appli -blocking false -buffering line -encoding utf-8
update
set update 0
set nb_ligne_vide 0
# Ecriture du rapport
set boucle 1
while {$boucle} {
# Lecture ligne
gets $appli line
if {[eof $appli] == 1} {set boucle 0}
# Si ligne complète...
if {[fblocked $appli] != 1} {
if { $line == "" } {
incr nb_ligne_vide
}
if {$line != "" | ($nb_ligne_vide > 1) } {
puts $line
incr update
set nb_ligne_vide 0
}
} else {
after 10
incr update
}
if { $update > 50 } {
set update 0
update
}
}
close $appli
method 2 (open with pipe)
set appli [open "|toto.exe 2>@ $logfile" r+]
fconfigure $appli -blocking false -buffering line -encoding utf-8
fileevent $appli readable [list pipe_questalint $appli]
proc pipe_questalint { appli } {
global done etat
if { [eof $appli] } {
close $appli
set done 1
} else {
if {[gets $appli line] >= 0} {
puts "TEST: $line"
}
}
}
vwait done
Using both method, I don't have any line displayed during program execution. Even if during the TCL program execution there is a windows command line displayed with all output generated by the tool executed by TCL.
If I launch the tool without tcl but using a command line in windows cmd.exe I can see ouput of the tool displayed in the same windows than the one I used to launch the program.
method2 (open + pipe) is working great under linux using the linux version of the same tool.
method 1 and 2 are working great also with other tool under linux and under windows. I don't know well the difference between both method, I don't know if one is better even if I guess that pipe method may be better optimized.
I also tested these code without the error redirection and I have the same problem. it is the first time that I meet this kind of problem whereas I did it successfully with more that 10 tools from different editors.
thanks a lot for your help
Upvotes: 2
Views: 83
Reputation: 137767
The Windows version of the program might be writing to the console directly; there is a whole separate API for that. (This is a trick that Tcl knows and uses itself when it believes it is appropriate to do so.) The equivalent on Linux would be if the runtime decided to replace stdin and stdout with opening /dev/tty
. It's hard to know for sure whether this is happening; there's a lot of complexity under the covers.
All that exec
can really do is to make the pipes and hook the programs up to them. It can't force the programs to use those pipes.
You could try getting hold of Expect-for-Windows and using that to run the subprocess... That might work.
Upvotes: 1