See Also edit
- Additional file commands
- Tips and tricks for processing the content in a channel.
- chan mode
- an example of extening the chan ensemble
- stacked channel
- transform
- ycl chan connect
- Connect the output of one channel to the input of another. Uses a separate thread to avoid deadlocks.
Synopsis edit
- chan action ?arg arg ...?
Documentation edit
- official reference
- TIP 208
- add chan
Description edit
Introduced in Tcl 8.5.chan provides various operations on a channel, including many that have been available using a mix of other commands. action indicates what to do with the channel. Any unique abbreviation for an action is acceptable. The valid actionss are:New actions (no analog in rest of Tcl)
- chan create mode cmdPrefix
- creates a channel using a cmdPrefix (e.g., an ensemble or object)
- chan pending mode channelId
- returns the number of bytes (of input or output, depending on mode) buffered internally
- chan pop channelId
- pop one transform off a stacked channel
- chan postevent channelId eventSpec
- generate event on channel (which it must be listening for)
- chan push channelId cmdPrefix
- stack a transform on top of the channel
- chan pipe
- create a standalone pipe and return a pair of file descriptors for its read and write ends, in this order (TIP [1], available in Tcl >= 8.6).
- chan truncate channelId ?length?
- truncate the file behind the channel
AMG: chan aggregates all the commands you'll need for working with channels, except creating traditional channels (it can only create pipes and reflected channels). Use open or socket or an extension command, same as always. If you find a core channel command not incorporated as a chan subcommand, please report it.
Renamed actions (available as another command as well)
- chan blocked channelId
- supercedes fblocked
- chan close channelId
- supercedes close
- chan configure channelId ?optionName? ?value? ?optionName value?...
- supercedes fconfigure
- chan copy inputChan outputChan ?options...?
- same as fcopy
- chan eof channelId
- supercedes eof
- chan event channelId event ?script?
- supercedes fileevent
- chan flush channelId
- supercedes flush
- chan gets channelId ?varName?
- supercedes gets
- chan names ?globPattern?
- supercedes file channels
- chan puts ?-nonewline? ?channelId? string
- supercedes puts
- chan read channelId ?numChars?
- chan read ?-nonewline? channelId
- supercedes read
- chan seek channelId offset ?origin?
- supercedes seek
- chan tell channelId
- supercedes tell
History edit
RS: History sometimes runs in circles... Tcl 2.1 didn't have commands dealing with channels. Peter da Silva added the "stream" extension, where one could writestream fp open $filename r set x [stream fp gets] stream fp closeLater, the parts of "stream" went into the core as separate commands. Still later, in 8.5, they get reunited again in chan, which arguably makes the command set leaner, but scripts wordier...