59 lines
3.3 KiB
HTML
59 lines
3.3 KiB
HTML
|
<HTML><HEAD><TITLE>Tcl Built-In Commands - puts manual page</TITLE></HEAD><BODY>
|
||
|
<H3><A NAME="M2">NAME</A></H3>
|
||
|
puts - Write to a channel
|
||
|
<H3><A NAME="M3">SYNOPSIS</A></H3>
|
||
|
<B>puts </B>?<B>-nonewline</B>? ?<I>channelId</I>? <I>string</I><BR>
|
||
|
<H3><A NAME="M4">DESCRIPTION</A></H3>
|
||
|
Writes the characters given by <I>string</I> to the channel given
|
||
|
by <I>channelId</I>.
|
||
|
<I>ChannelId</I> must be a channel identifier such as returned from a
|
||
|
previous invocation of <B><A HREF="../TkCmd/open.htm">open</A></B> or <B><A HREF="../TkCmd/socket.htm">socket</A></B>. It must have been opened
|
||
|
for output. If no <I>channelId</I> is specified then it defaults to
|
||
|
<B>stdout</B>. <B>Puts</B> normally outputs a newline character after
|
||
|
<I>string</I>, but this feature may be suppressed by specifying the
|
||
|
<B>-nonewline</B> switch.
|
||
|
<P>
|
||
|
Newline characters in the output are translated by <B>puts</B> to
|
||
|
platform-specific end-of-line sequences according to the current
|
||
|
value of the <B>-translation</B> option for the channel (for example,
|
||
|
on PCs newlines are normally replaced with carriage-return-linefeed
|
||
|
sequences; on Macintoshes newlines are normally replaced with
|
||
|
carriage-returns).
|
||
|
See the <B><A HREF="../TkCmd/fconfigure.htm">fconfigure</A></B> manual entry for a discussion on ways in
|
||
|
which <B><A HREF="../TkCmd/fconfigure.htm">fconfigure</A></B> will alter output.
|
||
|
<P>
|
||
|
Tcl buffers output internally, so characters written with <B>puts</B>
|
||
|
may not appear immediately on the output file or device; Tcl will
|
||
|
normally delay output until the buffer is full or the channel is
|
||
|
closed.
|
||
|
You can force output to appear immediately with the <B><A HREF="../TkCmd/flush.htm">flush</A></B>
|
||
|
command.
|
||
|
<P>
|
||
|
When the output buffer fills up, the <B>puts</B> command will normally
|
||
|
block until all the buffered data has been accepted for output by the
|
||
|
operating system.
|
||
|
If <I>channelId</I> is in nonblocking mode then the <B>puts</B> command
|
||
|
will not block even if the operating system cannot accept the data.
|
||
|
Instead, Tcl continues to buffer the data and writes it in the
|
||
|
background as fast as the underlying file or device can accept it.
|
||
|
The application must use the Tcl event loop for nonblocking output
|
||
|
to work; otherwise Tcl never finds out that the file or device is
|
||
|
ready for more output data.
|
||
|
It is possible for an arbitrarily large amount of data to be
|
||
|
buffered for a channel in nonblocking mode, which could consume a
|
||
|
large amount of memory.
|
||
|
To avoid wasting memory, nonblocking I/O should normally
|
||
|
be used in an event-driven fashion with the <B><A HREF="../TkCmd/fileevent.htm">fileevent</A></B> command
|
||
|
(don't invoke <B>puts</B> unless you have recently been notified
|
||
|
via a file event that the channel is ready for more output data).
|
||
|
|
||
|
<H3><A NAME="M5">SEE ALSO</A></H3>
|
||
|
<B><A HREF="../TkCmd/file.htm">file</A></B>, <B><A HREF="../TkCmd/fileevent.htm">fileevent</A></B>
|
||
|
<H3><A NAME="M6">KEYWORDS</A></H3>
|
||
|
<A href="../Keywords/C.htm#channel">channel</A>, <A href="../Keywords/N.htm#newline">newline</A>, <A href="../Keywords/O.htm#output">output</A>, <A href="../Keywords/W.htm#write">write</A>
|
||
|
<HR><PRE>
|
||
|
<A HREF="../copyright.htm">Copyright</A> © 1993 The Regents of the University of California.
|
||
|
<A HREF="../copyright.htm">Copyright</A> © 1994-1996 Sun Microsystems, Inc.
|
||
|
<A HREF="../copyright.htm">Copyright</A> © 1995-1997 Roger E. Critchlow Jr.</PRE>
|
||
|
</BODY></HTML>
|