From: pmarin on
I often need to redirect a tcl function/command that write to the
stdout, to another channel.
For example if I want to convert the output of a command to a string
(It could be very easy to do If I can do channel redirection).
How can I do it?

Example:

Imagine the command "toString":

>set output [toString { puts "hello"} ]

>set output
"hello"

Cheers.
Happy Christmas!
pmarin.
From: Jan Kandziora on
pmarin schrieb:
> I often need to redirect a tcl function/command that write to the
> stdout, to another channel.
> For example if I want to convert the output of a command to a string
> (It could be very easy to do If I can do channel redirection).
> How can I do it?
>
If you only need to capture puts (not fcopy or others), easiest way is to
redefine the puts procedure. See http://wiki.tcl.tk/8502 for an example
which redirects all puts output to a text widget.

Kind regards

Jan