Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added tcl to libs

File size: 2.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: gets.n,v 1.8 2005/05/10 18:34:00 kennykb Exp $
9'\"
10.so man.macros
11.TH gets n 7.5 Tcl "Tcl Built-In Commands"
12.BS
13'\" Note:  do not modify the .SH NAME line immediately below!
14.SH NAME
15gets \- Read a line from a channel
16.SH SYNOPSIS
17\fBgets \fIchannelId\fR ?\fIvarName\fR?
18.BE
19
20.SH DESCRIPTION
21.PP
22This command reads the next line from \fIchannelId\fR, returns everything
23in the line up to (but not including) the end-of-line character(s), and
24discards the end-of-line character(s).
25.PP
26\fIChannelId\fR must be an identifier for an open channel such as the
27Tcl standard input channel (\fBstdin\fR), the return value from an
28invocation of \fBopen\fR or \fBsocket\fR, or the result of a channel
29creation command provided by a Tcl extension. The channel must have
30been opened for input.
31.PP
32If \fIvarName\fR is omitted the line is returned as the result of the
33command.
34If \fIvarName\fR is specified then the line is placed in the variable by
35that name and the return value is a count of the number of characters
36returned.
37.PP
38If end of file occurs while scanning for an end of
39line, the command returns whatever input is available up to the end of file.
40If \fIchannelId\fR is in nonblocking mode and there is not a full
41line of input available, the command returns an empty string and
42does not consume any input.
43If \fIvarName\fR is specified and an empty string is returned in
44\fIvarName\fR because of end-of-file or because of insufficient
45data in nonblocking mode, then the return count is -1.
46Note that if \fIvarName\fR is not specified then the end-of-file
47and no-full-line-available cases can
48produce the same results as if there were an input line consisting
49only of the end-of-line character(s).
50The \fBeof\fR and \fBfblocked\fR commands can be used to distinguish
51these three cases.
52.SH "EXAMPLE"
53This example reads a file one line at a time and prints it out with
54the current line number attached to the start of each line.
55.PP
56.CS
57set chan [open "some.file.txt"]
58set lineNumber 0
59while {[\fBgets\fR $chan line] >= 0} {
60    puts "[incr lineNumber]: $line"
61}
62close $chan
63.CE
64
65.SH "SEE ALSO"
66file(n), eof(n), fblocked(n), Tcl_StandardChannels(3)
67
68.SH KEYWORDS
69blocking, channel, end of file, end of line, line, nonblocking, read
Note: See TracBrowser for help on using the repository browser.