Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/read.n @ 25

Last change on this file since 25 was 25, checked in by landauf, 16 years ago

added tcl to libs

File size: 3.5 KB
Line 
1'\"
2'\" Copyright (c) 1993 The Regents of the University of California.
3'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4'\"
5'\" See the file "license.terms" for information on usage and redistribution
6'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7'\"
8'\" RCS: @(#) $Id: read.n,v 1.15 2007/12/13 15:22:33 dgp Exp $
9'\"
10.so man.macros
11.TH read n 8.1 Tcl "Tcl Built-In Commands"
12.BS
13'\" Note:  do not modify the .SH NAME line immediately below!
14.SH NAME
15read \- Read from a channel
16.SH SYNOPSIS
17\fBread \fR?\fB\-nonewline\fR? \fIchannelId\fR
18.sp
19\fBread \fIchannelId numChars\fR
20.BE
21
22.SH DESCRIPTION
23.PP
24In the first form, the \fBread\fR command reads all of the data from
25\fIchannelId\fR up to the end of the file.  If the \fB\-nonewline\fR
26switch is specified then the last character of the file is discarded
27if it is a newline.  In the second form, the extra argument specifies
28how many characters to read.  Exactly that many characters will be
29read and returned, unless there are fewer than \fInumChars\fR left in
30the file; in this case all the remaining characters are returned.  If
31the channel is configured to use a multi-byte encoding, then the
32number of characters read may not be the same as the number of bytes
33read.
34.PP
35\fIChannelId\fR must be an identifier for an open channel such as the
36Tcl standard input channel (\fBstdin\fR), the return value from an
37invocation of \fBopen\fR or \fBsocket\fR, or the result of a channel
38creation command provided by a Tcl extension. The channel must have
39been opened for input.
40.PP
41If \fIchannelId\fR is in nonblocking mode, the command may not read as
42many characters as requested: once all available input has been read,
43the command will return the data that is available rather than
44blocking for more input.  If the channel is configured to use a
45multi-byte encoding, then there may actually be some bytes remaining
46in the internal buffers that do not form a complete character.  These
47bytes will not be returned until a complete character is available or
48end-of-file is reached.  The \fB\-nonewline\fR switch is ignored if
49the command returns before reaching the end of the file.
50.PP
51\fBRead\fR translates end-of-line sequences in the input into
52newline characters according to the \fB\-translation\fR option
53for the channel.
54See the \fBfconfigure\fR manual entry for a discussion on ways in
55which \fBfconfigure\fR will alter input.
56
57.SH "USE WITH SERIAL PORTS"
58'\" Note:  this advice actually applies to many versions of Tcl
59
60For most applications a channel connected to a serial port should be
61configured to be nonblocking: \fBfconfigure \fIchannelId \fB\-blocking
62\fI0\fR.  Then \fBread\fR behaves much like described above.  Care
63must be taken when using \fBread\fR on blocking serial ports:
64.TP
65\fBread \fIchannelId numChars\fR
66In this form \fBread\fR blocks until \fInumChars\fR have been received
67from the serial port.
68.TP
69\fBread \fIchannelId\fR
70In this form \fBread\fR blocks until the reception of the end-of-file
71character, see \fBfconfigure -eofchar\fR. If there no end-of-file
72character has been configured for the channel, then \fBread\fR will
73block forever.
74.SH "EXAMPLE"
75This example code reads a file all at once, and splits it into a list,
76with each line in the file corresponding to an element in the list:
77.CS
78set fl [open /proc/meminfo]
79set data [\fBread\fR $fl]
80close $fl
81set lines [split $data \en]
82.CE
83
84.SH "SEE ALSO"
85file(n), eof(n), fblocked(n), fconfigure(n), Tcl_StandardChannels(3)
86
87.SH KEYWORDS
88blocking, channel, end of line, end of file, nonblocking, read, translation, encoding
Note: See TracBrowser for help on using the repository browser.