Re: retrieve "puts" command result from C
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: retrieve "puts" command result from C

From: Michael Schlenker <schlenk@uni-oldenburg.de>
Date: Wed Mar 08 2006 - 17:56:51 CET

fabrice.dufour@gmail.com wrote:
> Thanks for this rapid answer.
>
> I just want to display the result in stdout and also get it in a char*

So the simplest way would be to redefine puts to return its argument and
read the command result. Everything else is way more complex and
probably overkill.

rename puts ::tcl::puts
proc puts {args} {
    # call the original command in a safe way
    # in Tcl 8.5 one would simply use:
    # ::tcl::puts {expand}$args
    eval [linsert $args 0 ::tcl::puts]

    # The value is the last element of args
    return [lindex $args end]
}

Now you have a puts that returns what it prints...

>
> I will give a look at memchan, but I want to "TCL compliant" as
> possible. So I will probably investigate the solution "redirect stdout
> to a Tcl_channel that does what I want"

Thats what memchan does. It provides channel types that write to
Tcl_Objs => char*...

Michael
Received on Sun Apr 30 02:27:49 2006