Thread from comp.lang.tcl (2 replies)
a trivial and complicated problem in TCL
Hi, I use > pkg_mkIndex -verbose . {*}$libs to build a 'pkgIndex.tcl' file … GOOD NOW I want to redirect the "stderr" output (-verbose) to stdout ... BAD I can't figure out a "trivial" solution for this simple task IN tcl. I know there are "exec/open" etc command there I can redirect the output of an EXTERNAL program but this is not for a tcl INTERNAL "proc" like "pkg_mkIndex". I know that I can start an second tclsh with the "pkg_mkIndex" and redirect the output BUT I search for an tcl INTERNAL solution. my CURRENT solution is way-to-over-engineerd → recreate the tcl "put" command and exchange "stderr" with "stdout" ========================================= # ERASE "stderr" from tcl output rename puts __tcl__puts proc puts {args} { set nxt [lindex $args 0] if {[string index $nxt 0] eq "-"} { set nnl $nxt set args [lassign $args -] } else { set nnl "" } set nxt [lindex $args 0] if {[llength [chan names $nxt]]} { if {$nxt eq "stderr"} { set chn stdout } else { set chn $nxt } set args [lassign $args -] } else { set chn "" } __tcl__puts {*}[concat $nnl $chn $args] } ======================================= What I look for is something like: > chan redirect /dev/stderr /dev/stdout which works without touching any TCL related "proc" stuff or spawn an extra shell. → any idea ?Click on article to view all threads in comp.lang.tcl
Re: a trivial and complicated problem in TCL
* aotto1968 <aotto1968@t-online.de> | I use > | > pkg_mkIndex -verbose . {*}$libs > | to build a 'pkgIndex.tcl' file … GOOD | NOW I want to redirect the "stderr" output (-verbose) to stdout ... BAD > | I can't figure out a "trivial" solution for this simple task IN tcl. Looking at the code for pkg_mkIndex, it uses 'tclLog' for the 'verbose' output. 'tclLog' itself is defined in init.tcl, with the explicit comment # Define a log command (which can be overwritten to log errors # differently, specially when stderr is not available) if {[namespace which -command tclLog] eq ""} { proc tclLog {string} { catch {puts s $string} } } So if you redefine proc tclLog {string} { catch {puts stdout $string} } prior to invoking pkg_mkIndex, it might "just work". Haven'd tried it, so YMMV. HTH R'Click on article to view all threads in comp.lang.tcl
Re: a trivial and complicated problem in TCL
On 8/12/24 14:45, aotto1968 wrote: > ... > my CURRENT solution is way-to-over-engineerd > → recreate the tcl "put" command and exchange "stderr" with "stdout" You could have studied the implementation of "pkg_mkIndex" and found that it uses a command "tclLog" for logging. Then you could have exchanged the "tclLog" command with the implementation of your choice. If this is over or under engineering depends solely on your own version of "tclLog". HTH, ChristianClick on article to view all threads in comp.lang.tcl