1Tcl_GetStdChannel(3) Tcl Library Procedures Tcl_GetStdChannel(3)
2
3
4
5______________________________________________________________________________
6
8 Tcl_GetStdChannel, Tcl_SetStdChannel - procedures for retrieving and
9 replacing the standard channels
10
12 #include <tcl.h>
13
14 Tcl_Channel
15 Tcl_GetStdChannel(type)
16
17 Tcl_SetStdChannel(channel, type)
18
19
21 int type (in) The identifier for the standard chan‐
22 nel to retrieve or modify. Must be
23 one of TCL_STDIN, TCL_STDOUT, or
24 TCL_STDERR.
25
26 Tcl_Channel channel (in) The channel to use as the new value
27 for the specified standard channel.
28_________________________________________________________________
29
30
32 Tcl defines three special channels that are used by various I/O related
33 commands if no other channels are specified. The standard input chan‐
34 nel has a channel name of stdin and is used by read and gets. The
35 standard output channel is named stdout and is used by puts. The stan‐
36 dard error channel is named stderr and is used for reporting errors.
37 In addition, the standard channels are inherited by any child processes
38 created using exec or open in the absence of any other redirections.
39
40 The standard channels are actually aliases for other normal channels.
41 The current channel associated with a standard channel can be retrieved
42 by calling Tcl_GetStdChannel with one of TCL_STDIN, TCL_STDOUT, or
43 TCL_STDERR as the type. The return value will be a valid channel, or
44 NULL.
45
46 A new channel can be set for the standard channel specified by type by
47 calling Tcl_SetStdChannel with a new channel or NULL in the channel
48 argument. If the specified channel is closed by a later call to
49 Tcl_Close, then the corresponding standard channel will automatically
50 be set to NULL.
51
52 If a non-NULL value for channel is passed to Tcl_SetStdChannel, then
53 that same value should be passed to Tcl_RegisterChannel, like so:
54 Tcl_RegisterChannel(NULL, channel);
55 This is a workaround for a misfeature in Tcl_SetStdChannel that it
56 fails to do some reference counting housekeeping. This misfeature can‐
57 not be corrected without contradicting the assumptions of some existing
58 code that calls Tcl_SetStdChannel.
59
60 If Tcl_GetStdChannel is called before Tcl_SetStdChannel, Tcl will con‐
61 struct a new channel to wrap the appropriate platform-specific standard
62 file handle. If Tcl_SetStdChannel is called before Tcl_GetStdChannel,
63 then the default channel will not be created.
64
65 If one of the standard channels is set to NULL, either by calling
66 Tcl_SetStdChannel with a NULL channel argument, or by calling Tcl_Close
67 on the channel, then the next call to Tcl_CreateChannel will automati‐
68 cally set the standard channel with the newly created channel. If more
69 than one standard channel is NULL, then the standard channels will be
70 assigned starting with standard input, followed by standard output,
71 with standard error being last.
72
73 See Tcl_StandardChannels for a general treatise about standard channels
74 and the behaviour of the Tcl library with regard to them.
75
76
78 Tcl_Close(3), Tcl_CreateChannel(3), Tcl_Main(3), tclsh(1)
79
80
82 standard channel, standard input, standard output, standard error
83
84
85
86Tcl 7.5 Tcl_GetStdChannel(3)