⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 openfilechnl.3

📁 tcl是工具命令语言
💻 3
📖 第 1 页 / 共 3 页
字号:
types.The channel mechanism is extensible to new channel types, byproviding a low level channel driver for the new type; the channel driverinterface is described in the manual entry for \fBTcl_CreateChannel\fR. Thechannel mechanism provides a buffering scheme modeled afterUnix's standard I/O, and it also allows for nonblocking I/O onchannels..PPThe procedures described in this manual entry comprise the C APIs of thegeneric layer of the channel architecture. For a description of the channeldriver architecture and how to implement channel drivers for new types ofchannels, see the manual entry for \fBTcl_CreateChannel\fR..SH TCL_OPENFILECHANNEL.PP\fBTcl_OpenFileChannel\fR opens a file specified by \fIfileName\fR andreturns a channel handle that can be used to perform input and output onthe file. This API is modeled after the \fBfopen\fR procedure ofthe Unix standard I/O library.The syntax and meaning of all arguments is similar to thosegiven in the Tcl \fBopen\fR command when opening a file.If an error occurs while opening the channel, \fBTcl_OpenFileChannel\fRreturns NULL and records a POSIX error code that can beretrieved with \fBTcl_GetErrno\fR.In addition, if \fIinterp\fR is non-NULL, \fBTcl_OpenFileChannel\fRleaves an error message in \fIinterp\fR's result after any error.  As of Tcl 8.4, the object-based API \fBTcl_FSOpenFileChannel\fR should be used in preference to \fBTcl_OpenFileChannel\fR wherever possible..PP.PPThe newly created channel is not registered in the supplied interpreter; toregister it, use \fBTcl_RegisterChannel\fR, described below.If one of the standard channels, \fBstdin, stdout\fR or \fBstderr\fR waspreviously closed, the act of creating the new channel also assigns it as areplacement for the standard channel..SH TCL_OPENCOMMANDCHANNEL.PP\fBTcl_OpenCommandChannel\fR provides a C-level interface to thefunctions of the \fBexec\fR and \fBopen\fR commands.It creates a sequence of subprocesses specifiedby the \fIargv\fR and \fIargc\fR arguments and returns a channel that canbe used to communicate with these subprocesses.The \fIflags\fR argument indicates what sort of communication willexist with the command pipeline..PPIf the \fBTCL_STDIN\fR flag is set then the standard input for thefirst subprocess will be tied to the channel: writing to the channelwill provide input to the subprocess.  If \fBTCL_STDIN\fR is not set,then standard input for the first subprocess will be the same as thisapplication's standard input.  If \fBTCL_STDOUT\fR is set thenstandard output from the last subprocess can be read from the channel;otherwise it goes to this application's standard output.  If\fBTCL_STDERR\fR is set, standard error output for all subprocesses isreturned to the channel and results in an error when the channel isclosed; otherwise it goes to this application's standard error.  If\fBTCL_ENFORCE_MODE\fR is not set, then \fIargc\fR and \fIargv\fR canredirect the stdio handles to override \fBTCL_STDIN\fR,\fBTCL_STDOUT\fR, and \fBTCL_STDERR\fR; if it is set, then it is anerror for argc and argv to override stdio channels for which\fBTCL_STDIN\fR, \fBTCL_STDOUT\fR, and \fBTCL_STDERR\fR have been set..PPIf an error occurs while opening the channel, \fBTcl_OpenCommandChannel\fRreturns NULL and records a POSIX error code that can be retrieved with\fBTcl_GetErrno\fR.In addition, \fBTcl_OpenCommandChannel\fR leaves an error message inthe interpreter's result if \fIinterp\fR is not NULL..PPThe newly created channel is not registered in the supplied interpreter; toregister it, use \fBTcl_RegisterChannel\fR, described below.If one of the standard channels, \fBstdin, stdout\fR or \fBstderr\fR waspreviously closed, the act of creating the new channel also assigns it as areplacement for the standard channel..SH TCL_MAKEFILECHANNEL.PP\fBTcl_MakeFileChannel\fR makes a \fBTcl_Channel\fR from an existing,platform-specific, file handle.The newly created channel is not registered in the supplied interpreter; toregister it, use \fBTcl_RegisterChannel\fR, described below.If one of the standard channels, \fBstdin, stdout\fR or \fBstderr\fR waspreviously closed, the act of creating the new channel also assigns it as areplacement for the standard channel..SH TCL_GETCHANNEL.PP\fBTcl_GetChannel\fR returns a channel given the \fIchannelName\fR used tocreate it with \fBTcl_CreateChannel\fR and a pointer to a Tcl interpreter in\fIinterp\fR. If a channel by that name is not registered in that interpreter,the procedure returns NULL. If the \fImodePtr\fR argument is not NULL, itpoints at an integer variable that will receive an OR-ed combination of\fBTCL_READABLE\fR and \fBTCL_WRITABLE\fR describing whether the channel isopen for reading and writing..PP\fBTcl_GetChannelNames\fR and \fBTcl_GetChannelNamesEx\fR write thenames of the registered channels to the interpreter's result as alist object.  \fBTcl_GetChannelNamesEx\fR will filter these namesaccording to the \fIpattern\fR.  If \fIpattern\fR is NULL, then itwill not do any filtering.  The return value is \fBTCL_OK\fR if noerrors occurred writing to the result, otherwise it is \fBTCL_ERROR\fR,and the error message is left in the interpreter's result..SH TCL_REGISTERCHANNEL.PP\fBTcl_RegisterChannel\fR adds a channel to the set of channels accessiblein \fIinterp\fR. After this call, Tcl programs executing in thatinterpreter can refer to the channel in input or output operations usingthe name given in the call to \fBTcl_CreateChannel\fR.  After this call,the channel becomes the property of the interpreter, and the caller shouldnot call \fBTcl_Close\fR for the channel; the channel will be closedautomatically when it is unregistered from the interpreter..PPCode executing outside of any Tcl interpreter can call\fBTcl_RegisterChannel\fR with \fIinterp\fR as NULL, to indicate that itwishes to hold a reference to this channel. Subsequently, the channel canbe registered in a Tcl interpreter and it will only be closed when thematching number of calls to \fBTcl_UnregisterChannel\fR have been made.This allows code executing outside of any interpreter to safely hold areference to a channel that is also registered in a Tcl interpreter..PPThis procedure interacts with the code managing the standardchannels. If no standard channels were initialized before the firstcall to \fBTcl_RegisterChannel\fR they will get initialized by thatcall. See \fBTcl_StandardChannels\fR for a general treatise aboutstandard channels and the behaviour of the Tcl library with regard tothem..SH TCL_UNREGISTERCHANNEL.PP\fBTcl_UnregisterChannel\fR removes a channel from the set of channelsaccessible in \fIinterp\fR. After this call, Tcl programs will no longer beable to use the channel's name to refer to the channel in that interpreter.If this operation removed the last registration of the channel in anyinterpreter, the channel is also closed and destroyed..PPCode not associated with a Tcl interpreter can call\fBTcl_UnregisterChannel\fR with \fIinterp\fR as NULL, to indicate to Tclthat it no longer holds a reference to that channel. If this is the lastreference to the channel, it will now be closed.  \fBTcl_UnregisterChannel\fRis very similar to \fBTcl_DetachChannel\fR except that it will alsoclose the channel if no further references to it exist..SH TCL_DETACHCHANNEL.PP\fBTcl_DetachChannel\fR removes a channel from the set of channelsaccessible in \fIinterp\fR. After this call, Tcl programs will no longer beable to use the channel's name to refer to the channel in that interpreter.Beyond that, this command has no further effect.  It cannot be used onthe standard channels (stdout, stderr, stdin), and will returnTCL_ERROR if passed one of those channels..PPCode not associated with a Tcl interpreter can call\fBTcl_DetachChannel\fR with \fIinterp\fR as NULL, to indicate to Tclthat it no longer holds a reference to that channel. If this is the lastreference to the channel, unlike \fBTcl_UnregisterChannel\fR, it will not be closed..SH TCL_ISSTANDARDCHANNEL.PP\fBTcl_IsStandardChannel\fR tests whether a channel is one of thethree standard channels, stdin, stdout or stderr.  If so, it returns1, otherwise 0..PPNo attempt is made to check whether the given channel or the standard channels are initialized or otherwise valid..SH TCL_CLOSE.PP\fBTcl_Close\fR destroys the channel \fIchannel\fR, which must denote acurrently open channel. The channel should not be registered in anyinterpreter when \fBTcl_Close\fR is called. Buffered output is flushed tothe channel's output device prior to destroying the channel, and anybuffered input is discarded.  If this is a blocking channel, the call doesnot return until all buffered data is successfully sent to the channel'soutput device.  If this is a nonblocking channel and there is bufferedoutput that cannot be written without blocking, the call returnsimmediately; output is flushed in the background and the channel will beclosed once all of the buffered data has been output.  In this case errorsduring flushing are not reported..PPIf the channel was closed successfully, \fBTcl_Close\fR returns \fBTCL_OK\fR.If an error occurs, \fBTcl_Close\fR returns \fBTCL_ERROR\fR and records aPOSIX error code that can be retrieved with \fBTcl_GetErrno\fR.If the channel is being closed synchronously and an error occurs duringclosing of the channel and \fIinterp\fR is not NULL, an error message isleft in the interpreter's result..PPNote: it is not safe to call \fBTcl_Close\fR on a channel that has beenregistered using \fBTcl_RegisterChannel\fR; see the documentation for\fBTcl_RegisterChannel\fR, above, for details. If the channel has everbeen given as the \fBchan\fR argument in a call to\fBTcl_RegisterChannel\fR, you should instead use\fBTcl_UnregisterChannel\fR, which will internally call \fBTcl_Close\fRwhen all calls to \fBTcl_RegisterChannel\fR have been matched bycorresponding calls to \fBTcl_UnregisterChannel\fR..VS 8.1 br.SH "TCL_READCHARS AND TCL_READ".PP\fBTcl_ReadChars\fR consumes bytes from \fIchannel\fR, converting the bytesto UTF-8 based on the channel's encoding and storing the produced data in \fIreadObjPtr\fR's string representation.  The return value of\fBTcl_ReadChars\fR is the number of characters, up to \fIcharsToRead\fR,that were stored in \fIreadObjPtr\fR.  If an error occurs while reading, thereturn value is \-1 and \fBTcl_ReadChars\fR records a POSIX error code thatcan be retrieved with \fBTcl_GetErrno\fR..PPThe return value may be smaller than the value to read, indicating that lessdata than requested was available.  This is called a \fIshort read\fR.  Inblocking mode, this can only happen on an end-of-file.  In nonblocking mode,a short read can also occur if there is not enough input currentlyavailable:  \fBTcl_ReadChars\fR returns a short count rather than waitingfor more data..PPIf the channel is in blocking mode, a return value of zero indicates anend-of-file condition.  If the channel is in nonblocking mode, a returnvalue of zero indicates either that no input is currently available or anend-of-file condition.  Use \fBTcl_Eof\fR and \fBTcl_InputBlocked\fR to tellwhich of these conditions actually occurred..PP\fBTcl_ReadChars\fR translates the various end-of-line representations intothe canonical \fB\en\fR internal representation according to the currentend-of-line recognition mode.  End-of-line recognition and the variousplatform-specific modes are described in the manual entry for the Tcl\fBfconfigure\fR command..PP

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -