TCL - How do I print on-screen messages that are printed during the execution of the exec command?

Suppose I want to execute a script and / or executable file by printing runtime execution output.

When I do this:

set log [exec ./executable_file]
puts $log

Then it waits a lot of time and then prints all at once. But I need a print while I work. How can i do this?

+5
source share
3 answers

Not ideal (since an external file is required for recording):

set log [exec executable_file | tee log.txt >@stdout]

The output will be displayed immediately, at the same time, saved in "log.txt". If you don't care about saving the output:

set log [exec executable_file >@stdout]
+8
source

open "| ..." , :

proc ReadLine fd {
  if {[gets $fd line] < 0} {
    if {[chan eof $fd]} {
      chan close $fd
      set ::forever now
      return
    }
  }
  puts $line
}

set fd [open "| ./executable_file"]
chan configure $fd -blocking no
chan event $fd readable [list ReadLine $fd]

vwait forever

. .

, , , vwait .

, , [puts] , ( ), "", (ReadLine ) .

+2

, , tail -f logfile.txt, .

0

All Articles