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