summaryrefslogtreecommitdiffstats
path: root/doc/StdChannels.3
blob: 1398d7806280550d4933e44518dce54127ffd867 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'\"
'\" Copyright (c) 2001 by ActiveState Corporation
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\" 
'\" RCS: @(#) $Id: StdChannels.3,v 1.4 2001/11/10 02:34:57 hobbs Exp $
'\" 
.so man.macros
.TH "Standard Channels" 3 7.5 Tcl "Tcl Library Procedures"
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
Tcl_StandardChannels \- How the Tcl library deals with the standard channels
.SH SYNOPSIS
.PP
This page explains the initialization and use of standard channels in
the Tcl library.
.PP
The term \fIstandard channels\fR comes out of the Unix world and
refers to the three channels automatically opened by the OS for
each new application. They are \fBstdin\fR, \fBstdout\fR and
\fBstderr\fR. The first is the standard input an application can read
from, the other two refer to writable channels, one for regular
output and the other for error messages.
.PP
Tcl generalizes this concept in a cross-platform way and
exposes standard channels to the script level.
.SH APIs
.PP
The public API procedures dealing directly with standard channels are
\fBTcl_GetStdChannel\fR and \fBTcl_SetStdChannel\fR. Additional public
APIs to consider are \fBTcl_RegisterChannel\fR,
\fBTcl_CreateChannel\fR and \fBTcl_GetChannel\fR.
.SH Initialization of Tcl standard channels
.PP
Standard channels are initialized by the Tcl library in three cases:
when explicitly requested, when implicitly required before returning
channel information, or when implicitly required during registration
of a new channel.
.PP
These cases differ in how they handle unavailable platform- specific
standard channels.  (A channel is not "available" if it could not be
successfully opened; for example, in a Tcl application run as a
Windows NT service.)
.TP
1)
A single standard channel is initialized when it is explicitly
specified in a call to \fBTcl_SetStdChannel\fR.  The state of the
other standard channels are unaffected.
.sp
Missing platform-specific standard channels do not matter here. This
approach is not available at the script level.
.TP
2)
All uninitialized standard channels are initialized to
platform-specific default values:
.RS
.TP
(a)
when open channels are listed with \fBTcl_GetChannelNames\fR (or the
\fBfile channels\fR script command), or
.TP
(b)
when information about any standard channel is requested with a call
to \fBTcl_GetStdChannel\fR, or with a call to \fBTcl_GetChannel\fR
which specifies one of the standard names (\fBstdin\fR, \fBstdout\fR
and \fBstderr\fR).
.RE
.sp
.RS
In case of missing platform-specific standard channels, the Tcl
standard channels are considered as initialized and then immediately
closed. This means that the first three Tcl channels then opened by
the application are designated as the Tcl standard channels.
.RE
.TP
3)
All uninitialized standard channels are initialized to
platform-specific default values when a user-requested channel is
registered with \fBTcl_RegisterChannel\fR.
.sp
In case of unavailable platform-specific standard channels the channel
whose creation caused the initialization of the Tcl standard channels
is made a normal channel.  The next three Tcl channels opened by the
application are designated as the Tcl standard channels.  In other
words, of the first four Tcl channels opened by the application the
second to fourth are designated as the Tcl standard channels.
.PP
.SH Re-initialization of Tcl standard channels
.PP
Once a Tcl standard channel is initialized through one of the methods
above, closing this Tcl standard channel will cause the next call to
\fBTcl_CreateChannel\fR to make the new channel the new standard
channel, too. If more than one Tcl standard channel was closed
\fBTcl_CreateChannel\fR will fill the empty slots in the order
\fBstdin\fR, \fBstdout\fR and \fBstderr\fR.
.PP
\fBTcl_CreateChannel\fR will not try to reinitialize an empty slot if
that slot was not initialized before. It is this behavior which
enables an application to employ method 1 of initialization, i.e. to
create and designate their own Tcl standard channels.

.SH tclsh
.PP
The Tcl shell (or rather \fBTcl_Main\fR) uses method 2 to initialize
the standard channels.

.SH wish
.PP
The windowing shell (or rather \fBTk_MainEx\fR) uses method 1 to
initialize the standard channels (See \fBTk_InitConsoleChannels\fR)
on non-Unix platforms.  On Unix platforms, \fBTk_MainEx\fR implicitly
uses method 2 to initialize the standard channels.

.SH "SEE ALSO"
Tcl_CreateChannel(3), Tcl_RegisterChannel(3), Tcl_GetChannel(3), Tcl_GetStdChannel(3), Tcl_SetStdChannel(3), Tk_InitConsoleChannels(3), tclsh(1), wish(1), Tcl_Main(3), Tk_MainEx(3)

.SH KEYWORDS
standard channels