1gets(n)                      Tcl Built-In Commands                     gets(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       gets - Read a line from a channel
9

SYNOPSIS

11       gets channelId ?varName?
12______________________________________________________________________________
13
14

DESCRIPTION

16       This  command reads the next line from channelId, returns everything in
17       the line up to (but not including) the  end-of-line  character(s),  and
18       discards the end-of-line character(s).
19
20       ChannelId  must  be  an  identifier for an open channel such as the Tcl
21       standard input channel (stdin), the return value from an invocation  of
22       open or socket, or the result of a channel creation command provided by
23       a Tcl extension. The channel must have been opened for input.
24
25       If varName is omitted the line is returned as the result  of  the  com‐
26       mand.   If varName is specified then the line is placed in the variable
27       by that name and the return value is a count of the number  of  charac‐
28       ters returned.
29
30       If  end  of  file occurs while scanning for an end of line, the command
31       returns whatever input is available up to the end of  file.   If  chan‐
32       nelId  is  in  non-blocking  mode and there is not a full line of input
33       available, the command returns an empty string and does not consume any
34       input.  If varName is specified and an empty string is returned in var‐
35       Name because of end-of-file or because of  insufficient  data  in  non-
36       blocking  mode,  then  the return count is -1.  Note that if varName is
37       not specified then the end-of-file and no-full-line-available cases can
38       produce the same results as if there were an input line consisting only
39       of the end-of-line character(s).  The eof and fblocked commands can  be
40       used to distinguish these three cases.
41

EXAMPLE

43       This example reads a file one line at a time and prints it out with the
44       current line number attached to the start of each line.
45
46              set chan [open "some.file.txt"]
47              set lineNumber 0
48              while {[gets $chan line] >= 0} {
49                  puts "[incr lineNumber]: $line"
50              }
51              close $chan
52
53

SEE ALSO

55       file(n), eof(n), fblocked(n), Tcl_StandardChannels(3)
56
57

KEYWORDS

59       blocking, channel, end of file, end of line, line, non-blocking, read
60
61
62
63Tcl                                   7.5                              gets(n)
Impressum