I have the following scenario:
if { [catch { exec echo calling a BIG script } exec_msg] } {
puts "NOK"
puts "output of the BIG script: $exec_msg"
} else {
puts "OK"
puts "output of the BIG script: $exec_msg"
}
Are there any solutions to print the $exec_msg in real-time, in sync with the execution of the BIG script?
If you do:
exec echo calling a BIG script >@stdout
# Everything wrapped around the exec is the same; I omit it for brevity
Then the output from the script will be written straight to standard out. However, you lose the ability to read it from your Tcl script. To also read it from the script, you can try (on Unix):
exec echo calling a BIG script | tee /dev/tty
However that will tend to delay the output until it accumulates a few kilobytes at a time (a feature of how most programs do output to non-terminals). Fixing that requires the use of Expect, which is a lot more complicated, or maybe creating a pipeline and handling it asynchronously. It's all a substantial step up in trickiness from what you've been doing, and it's because you're starting to fight against how the programs work naturally. To be frank, you're better off avoiding that sort of thing if you don't really need it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With