Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / share / tcl / help / tcl / files / gets
1 NAME
2 gets - Read a line from a channel
3
4 SYNOPSIS
5 gets channelId ?varName?
6
7
8 DESCRIPTION
9 This command reads the next line from channelId, returns everything in
10 the line up to (but not including) the end-of-line character(s), and
11 discards the end-of-line character(s).
12
13 ChannelId must be an identifier for an open channel such as the Tcl
14 standard input channel (stdin), the return value from an invocation of
15 open or socket, or the result of a channel creation command provided by
16 a Tcl extension. The channel must have been opened for input.
17
18 If varName is omitted the line is returned as the result of the com-
19 mand. If varName is specified then the line is placed in the variable
20 by that name and the return value is a count of the number of charac-
21 ters returned.
22
23 If end of file occurs while scanning for an end of line, the command
24 returns whatever input is available up to the end of file. If chan-
25 nelId is in nonblocking mode and there is not a full line of input
26 available, the command returns an empty string and does not consume any
27 input. If varName is specified and an empty string is returned in var-
28 Name because of end-of-file or because of insufficient data in non-
29 blocking mode, then the return count is -1. Note that if varName is
30 not specified then the end-of-file and no-full-line-available cases can
31 produce the same results as if there were an input line consisting only
32 of the end-of-line character(s). The eof and fblocked commands can be
33 used to distinguish these three cases.
34
35 EXAMPLE
36 This example reads a file one line at a time and prints it out with the
37 current line number attached to the start of each line.
38
39 set chan [open "some.file.txt"]
40 set lineNumber 0
41 while {[gets $chan line] >= 0} {
42 puts "[incr lineNumber]: $line"
43 }
44 close $chan
45
46
47 SEE ALSO
48 file(n), eof(n), fblocked(n), Tcl_StandardChannels(3)
49
50
51 KEYWORDS