read.n
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:4k
- '"
- '" Copyright (c) 1993 The Regents of the University of California.
- '" Copyright (c) 1994-1996 Sun Microsystems, Inc.
- '"
- '" See the file "license.terms" for information on usage and redistribution
- '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- '"
- '" RCS: @(#) $Id: read.n,v 1.7.8.1 2004/10/27 14:23:57 dkf Exp $
- '"
- .so man.macros
- .TH read n 8.1 Tcl "Tcl Built-In Commands"
- .BS
- '" Note: do not modify the .SH NAME line immediately below!
- .SH NAME
- read - Read from a channel
- .SH SYNOPSIS
- fBread fR?fB-nonewlinefR? fIchannelIdfR
- .sp
- fBread fIchannelId numCharsfR
- .BE
- .SH DESCRIPTION
- .PP
- In the first form, the fBreadfR command reads all of the data from
- fIchannelIdfR up to the end of the file. If the fB-nonewlinefR
- switch is specified then the last character of the file is discarded
- if it is a newline. In the second form, the extra argument specifies
- how many characters to read. Exactly that many characters will be
- read and returned, unless there are fewer than fInumCharsfR left in
- the file; in this case all the remaining characters are returned. If
- the channel is configured to use a multi-byte encoding, then the
- number of characters read may not be the same as the number of bytes
- read.
- .PP
- .VS
- fIChannelIdfR must be an identifier for an open channel such as the
- Tcl standard input channel (fBstdinfR), the return value from an
- invocation of fBopenfR or fBsocketfR, or the result of a channel
- creation command provided by a Tcl extension. The channel must have
- been opened for input.
- .VE
- .PP
- If fIchannelIdfR is in nonblocking mode, the command may not read as
- many characters as requested: once all available input has been read,
- the command will return the data that is available rather than
- blocking for more input. If the channel is configured to use a
- multi-byte encoding, then there may actually be some bytes remaining
- in the internal buffers that do not form a complete character. These
- bytes will not be returned until a complete character is available or
- end-of-file is reached. The fB-nonewlinefR switch is ignored if
- the command returns before reaching the end of the file.
- .PP
- fBReadfR translates end-of-line sequences in the input into
- newline characters according to the fB-translationfR option
- for the channel.
- See the fBfconfigurefR manual entry for a discussion on ways in
- which fBfconfigurefR will alter input.
- .SH "USE WITH SERIAL PORTS"
- '" Note: this advice actually applies to many versions of Tcl
- For most applications a channel connected to a serial port should be
- configured to be nonblocking: fBfconfigure fIchannelId fB-blocking
- fI0fR. Then fBreadfR behaves much like described above. Care
- must be taken when using fBreadfR on blocking serial ports:
- .TP
- fBread fIchannelId numCharsfR
- In this form fBreadfR blocks until fInumCharsfR have been received
- from the serial port.
- .TP
- fBread fIchannelIdfR
- In this form fBreadfR blocks until the reception of the end-of-file
- character, see fBfconfigure -eofcharfR. If there no end-of-file
- character has been configured for the channel, then fBreadfR will
- block forever.
- .SH "EXAMPLE"
- This example code reads a file all at once, and splits it into a list,
- with each line in the file corresponding to an element in the list:
- .CS
- set fl [open /proc/meminfo]
- set data [fBreadfR $fl]
- close $fl
- set lines [split $data \n]
- .CE
- .SH "SEE ALSO"
- file(n), eof(n), fblocked(n), fconfigure(n), Tcl_StandardChannels(3)
- .SH KEYWORDS
- blocking, channel, end of line, end of file, nonblocking, read, translation, encoding