chan puts
Writes a string and a newline to a channel.
chan puts ?-nonewline? ?CHAN? STRING
Description
Writes STRING and a newline to CHAN, by default stdout. The bytes go to the buffer of the channel, and out with chan flush, chan close, or a full buffer. The channel must be open for writing.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| CHAN | channel | stdout | The channel to write to. |
| STRING | string | required | The text to write. |
Options
| Option | Type | Default | Summary |
|---|---|---|---|
-nonewline | flag | none | Writes no newline after the string. |
-nonewline
Writes no newline after the string.
Writes STRING as it is, with no newline at its end.
% set f [open n.txt w]; chan puts -nonewline $f x; chan close $f
> file size n.txt
1A flag has no value to check.
Returns
An empty string.
Examples
% set f [open a.txt w]; chan puts $f hello; chan close $f
> file size a.txt
6
% chan puts stdout hi
hi
Errors
# The example puts fileN in place of the name of the channel, since the name changes from run to run.
% set f [open b.txt w]; chan close $f
> set f [open b.txt]
> catch {chan puts $f x} m
> chan close $f
> error [regsub {file\d+} $m fileN]
channel "fileN" wasn't opened for writing
-errorcode NONE
% chan puts
wrong # args: should be "chan puts ?-nonewline? ?channelId? string"
-errorcode TCL WRONGARGS
Facts
- Capability
channels. A new interpreter does not have it until the host turns it on.- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1