Updated 2014-11-12 20:16:21 by dkf
file channels ?pattern?

If pattern isn't specified, returns a list of names of all registered open channels in this interpreter. If pattern is specified, only those names matching pattern are returned. Matching is determined using the same rules as for string match.

This should really be channel names ?pattern? since it returns more than just files: also sockets, stdin, stdout, etc). As of Tcl 8.5, it indeed also comes under the name chan names, which is ugly but probably close enough.

AMG: Ugly? How so?

The pattern is somewhat useful, in that it allows you to find only open sockets (use a pattern of sock*) or reflected channels (use a pattern of rc*) but otherwise it can only really be used to determine non-destructively whether a channel is still open (i.e., still existing). What it currently can't do is tell you whether a channel is a pipe or not; this may change in the future.

See also edit


RS 2008-04-07: Looking at the result of file channels, e.g. from a console, can help to detect bugs where files were opened but not closed, which can "leak" considerable memory.