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

NAME

8       puts - Write to a channel
9

SYNOPSIS

11       puts ?-nonewline? ?channelId? string
12_________________________________________________________________
13
14

DESCRIPTION

16       Writes  the  characters  given  by string to the channel given by chan‐
17       nelId.
18
19       ChannelId must be an identifier for an open channel such as a Tcl stan‐
20       dard channel (stdout or stderr), the return value from an invocation of
21       open or socket, or the result of a channel creation command provided by
22       a Tcl extension. The channel must have been opened for output.
23
24       If  no channelId is specified then it defaults to stdout. Puts normally
25       outputs a newline character after string, but this feature may be  sup‐
26       pressed by specifying the -nonewline switch.
27
28       Newline  characters  in  the output are translated by puts to platform-
29       specific end-of-line sequences according to the current  value  of  the
30       -translation  option  for the channel (for example, on PCs newlines are
31       normally replaced with  carriage-return-linefeed  sequences.   See  the
32       fconfigure  manual  entry  for a discussion on ways in which fconfigure
33       will alter output.
34
35       Tcl buffers output internally, so characters written with puts may  not
36       appear  immediately  on  the  output file or device;  Tcl will normally
37       delay output until the buffer is full or the channel  is  closed.   You
38       can force output to appear immediately with the flush command.
39
40       When  the  output buffer fills up, the puts command will normally block
41       until all the buffered data has been accepted for output by the operat‐
42       ing  system.  If channelId is in nonblocking mode then the puts command
43       will not block even if the operating system  cannot  accept  the  data.
44       Instead,  Tcl  continues  to buffer the data and writes it in the back‐
45       ground as fast as the underlying file or device  can  accept  it.   The
46       application must use the Tcl event loop for nonblocking output to work;
47       otherwise Tcl never finds out that the file or device is ready for more
48       output data.  It is possible for an arbitrarily large amount of data to
49       be buffered for a channel in nonblocking mode, which  could  consume  a
50       large  amount  of  memory.   To  avoid  wasting memory, nonblocking I/O
51       should normally be used in an event-driven fashion with  the  fileevent
52       command  (do not invoke puts unless you have recently been notified via
53       a file event that the channel is ready for more output data).
54

EXAMPLES

56       Write a short message to the console (or wherever stdout is directed):
57              puts "Hello, World!"
58
59       Print a message in several parts:
60              puts -nonewline "Hello, "
61              puts "World!"
62
63       Print a message to the standard error channel:
64              puts stderr "Hello, World!"
65
66       Append a log message to a file:
67              set chan [open my.log a]
68              set timestamp [clock format [clock seconds]]
69              puts $chan "$timestamp - Hello, World!"
70              close $chan
71
72

SEE ALSO

74       file(n), fileevent(n), Tcl_StandardChannels(3)
75
76

KEYWORDS

78       channel, newline, output, write
79
80
81
82Tcl                                   7.5                              puts(n)
Impressum