Tcl_GetStdChannel, Tcl_SetStdChannel − procedures for retrieving and replacing the standard channels


#include <tcl.h>


Tcl_SetStdChannel(channel, type)


int type (in)

The identifier for the standard channel to retrieve or modify. Must be one of TCL_STDIN, TCL_STDOUT, or TCL_STDERR.

Tcl_Channel channel (in)

The channel to use as the new value for the specified standard channel.



Tcl defines three special channels that are used by various I/O related commands if no other channels are specified. The standard input channel has a channel name of stdin and is used by read and gets. The standard output channel is named stdout and is used by puts. The standard error channel is named stderr and is used for reporting errors. In addition, the standard channels are inherited by any child processes created using exec or open in the absence of any other redirections.

The standard channels are actually aliases for other normal channels. The current channel associated with a standard channel can be retrieved by calling Tcl_GetStdChannel with one of TCL_STDIN, TCL_STDOUT, or TCL_STDERR as the type. The return value will be a valid channel, or NULL.

A new channel can be set for the standard channel specified by type by calling Tcl_SetStdChannel with a new channel or NULL in the channel argument. If the specified channel is closed by a later call to Tcl_Close, then the corresponding standard channel will automatically be set to NULL.

If a non-NULL value for channel is passed to Tcl_SetStdChannel, then that same value should be passed to Tcl_RegisterChannel, like so:

Tcl_RegisterChannel(NULL, channel);

This is a workaround for a misfeature in Tcl_SetStdChannel that it fails to do some reference counting housekeeping. This misfeature cannot be corrected without contradicting the assumptions of some existing code that calls Tcl_SetStdChannel.

If Tcl_GetStdChannel is called before Tcl_SetStdChannel, Tcl will construct a new channel to wrap the appropriate platform-specific standard file handle. If Tcl_SetStdChannel is called before Tcl_GetStdChannel, then the default channel will not be created.

If one of the standard channels is set to NULL, either by calling Tcl_SetStdChannel with a NULL channel argument, or by calling Tcl_Close on the channel, then the next call to Tcl_CreateChannel will automatically set the standard channel with the newly created channel. If more than one standard channel is NULL, then the standard channels will be assigned starting with standard input, followed by standard output, with standard error being last.

See Tcl_StandardChannels for a general treatise about standard channels and the behaviour of the Tcl library with regard to them.


Tcl_Close(3), Tcl_CreateChannel(3), Tcl_Main(3), tclsh(1)


standard channel, standard input, standard output, standard error

More Linux Commands

tee(2) - duplicating pipe content - Linux manual page.......
tee() duplicates up to len bytes of data from the pipe referred to by the file descriptor fd_in to the pipe referred to by the file descriptor fd_out. It does n

rpcdebug(8) - set and clear NFS and RPC kernel debug flags
The rpcdebug command allows an administrator to set and clear the Linux kernels NFS client and server debug flags. Setting these flags causes the kernel to emit

XCompositeVersion(3) - X Composite Extension library........
The composite extension provides several related mechanisms: Per-hierarchy storage The rendering of an entire hierarchy of windows is redirected to off-screen s

TAP::Formatter::Console(3pm) - Harness output delegate for d
TAP::Formatter::Console.3pm - This provides console orientated output formatting for TAP::Harness. SYNOPSIS use TAP::Formatter::Console; my $harness = TAP::Form

pnmtoddif(1) - Convert a PNM image to DDIF format (ManPage)
This program is part of Netpbm(1) pnmtoddif takes a PNM image and converts it into a DDIF image file. pnmtoddif writes PBM format (bitmap) data as a 1 bit DDIF,

newusers(8) update and create new users in batch (Man Page)
The newusers command reads a file (or the standard input by default) and uses this information to update a set of existing users or to create new users. Each li

git-stripspace(1) - Filter out empty lines - Linux man page
Clean the input in the manner used by Git for text such as commit messages, notes, tags and branch descriptions. With no arguments, this will: * remove trailing

readcd(1) - read or write data Compact Discs (Man Page).....
Readom is used to read or write Compact Discs. The device refers to a device location similar to the one used in the wodim command. Refer to its manpage for det

pam_unix2(8) - Standard PAM module for traditional password
The pam_unix2 PAM module is for traditional password authentication. It uses standard calls from the glibc NSS libraries to retrieve and set account information

rename(1) - rename files (Commands - Linux manual page).....
rename will rename the specified files by replacing the first occurrence of expression in their name by replacement. OPTIONS -v, --verbose Give visual feedback

xlyap(6x) - display an array of Lyapunov exponents graphical
xlyap generates and graphically displays an array of Lyapunov exponents for a variety of iterated periodically forced non-linear maps of the unit interval. OPTI

XNextEvent(3) - select events by type - Linux manual page...
The XNextEvent function copies the first event from the event queue into the specified XEvent structure and then removes it from the queue. If the event queue i

We can't live, work or learn in freedom unless the software we use is free.