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.

Methods

(eq) other

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

(sink)()

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"

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.

Parameters

NameTypeDescription
data (Str | Bin) Bytes to write.

Returns

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

Errors

Exception Condition
TypeError data is not a Str or Bin

Example

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