2

For complicated reasons I have to hijack the "puts" routine. I would like to do different things based on what "stream" is

proc myPuts { stream msg } {

      if < stream is stdout >
          ....
      elseif < stream is stderr >
           ...
      else
           ...

}

Is there some way to know if the stream argument is stdout, stderr or a file from inside TCL?

Thanks,

user2410881
  • 143
  • 1
  • 7

1 Answers1

1

To the best of my knowledge, the stdout stream in Tcl is "stdout", and stderr is "stderr". If one does a puts $stream "string" with $stream having a value of "stdout", it goes to stdout; similarly with stderr.

The normal call to puts treats the stream argument as optional; your myPuts will need to do the same, and treat a missing operand as stdout. Beyond that, I believe it's just a matter of

if {$stream eq "stdout"} {
    # do your stdout thing
} elseif {$stream eq "stderr"} {
    # do your stderr thing
} else {
    # do your file handle thing
}
Erik Johnson
  • 1,136
  • 6
  • 17