Skip to content

Stdout

The process's standard output.

Obtained as shell.stdout.

Always writes to the real stream. Naming this handle is how you opt out of terminal takeover; use term.console to follow it instead.

A function that accepts an Io, such as compress.compress, writes to the stream directly. Writes from every source take turns, so a write's pieces are never split by another one.

Inherits from: io.Io

Fields

writable @ Bool [get]

Whether the stream writes, which it always does.

Methods

(eq) other -> Bool

Compares two handles. All instances are interchangeable, so any two are equal.

Parameters

NameTypeDescription
other Value

(sink)() -> Stdout

Accepts values as a sink, so this handle can be the target of a pipeline or of strand.put.

A value contributes exactly its own bytes and nothing else: no line ending is appended and none is translated. put differs from write only in stringifying values that are neither a Str nor a Bin rather than rejecting them, so put 42 writes 42 the way echo would.

To terminate values, say so with precrimp:

shell.stdout.put "hello"          # writes "hello"

let lines = shell.stdout.precrimp()
lines.put "hello"                 # writes "hello\n"

close()

Flushes, as flush does. The process's output stays open.

flush()

Flushes buffered output to the stream.

Worth calling when interleaving with unbuffered console output, whose ordering relative to buffered stdout is otherwise not guaranteed. The interpreter flushes on exit.

write *data -> Int

Writes bytes verbatim, given in pieces, which stay together.

Parameters

NameTypeDescription
*data (Str | Bin) Bytes to write.

Returns

Int - Bytes written, which is all of them. For a Str this is the UTF-8 byte count, not the character count.

Errors

Exception Condition
TypeError A piece is not a Str or Bin

Example

shell.stdout.write "no newline"
shell.stdout.write b"\x00\x01\xff"
shell.stdout.write $line "\n"
assert_eq (shell.stdout.write "héllo") 6