Skip to content
Topaz6.0 · Before release
Download

Search documentation

Specification 6.0 · Not released · Tested product 5.21.3

Use arrow keys to choose a result. Press Enter to open.

Type an API name, diagnostic number, rule, or project topic.

    Library

    std.io.readStdin

    Reads from standard input.

    readStdin() -> string
    Module
    std.io
    Receiver
    Not applicable
    Minimum arity
    0
    Maximum arity
    0

    Declaration and parameters

    Link

    Availability

    Included by default: Pending

    Import std.io in language mode 5.21.

    The current compiler selects std/io.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.

    Source evidence

    Receiver

    Parameter constraints

    readStdin reads the remaining standard input bytes through EOF. UTF-8 validity and text preservation follow UTF-8 decoding. It does not append or remove a newline.

    No remaining bytes produces an empty string. A later call reads from the stream position left by the earlier call and therefore returns an empty string at EOF. A terminal follows the same EOF rule as redirected input.

    The call may wait for input or EOF. Reading consumes input even when the result is later discarded. A host read failure or invalid UTF-8 produces a structured runtime fault at the readStdin call because the function returns a string rather than a Result.

    The Topaz 6.0 host input fault is TPZ4008. Its primary location is the readStdin call.

    Result

    The declared result type is string.

    Effects

    Failures

    Result and effects

    Link

    Consume the remaining standard input through EOF as strict UTF-8 text. Preserve whitespace and return empty text when no bytes remain.

    Related entries

    Link

    std.io

    Read standard input through its end

    Link
    Ruletopaz.stdlib.contract.stdin-consumption.rule

    Read standard input through its end

    readStdin reads the remaining standard input bytes through EOF. UTF-8 validity and text preservation follow UTF-8 decoding. It does not append or remove a newline.

    No remaining bytes produces an empty string. A later call reads from the stream position left by the earlier call and therefore returns an empty string at EOF. A terminal follows the same EOF rule as redirected input.

    The call may wait for input or EOF. Reading consumes input even when the result is later discarded. A host read failure or invalid UTF-8 produces a structured runtime fault at the readStdin call because the function returns a string rather than a Result.

    The Topaz 6.0 host input fault is TPZ4008. Its primary location is the readStdin call.

    Why

    Standard input is a stream shared with the host. Consuming it once gives EOF one meaning and lets terminal and redirected input obey the same rule. Strict UTF-8 prevents malformed bytes from silently becoming different text.

    Source evidence

    Preserve redirected text and its line endings

    Link
    main.tpzPreserve redirected text and its line endingsOpen in Playground
    1. import std.io
    2. let text = io.readStdin()
    3. io.writeLine(text)
    Expected outputexit 0
      alpha
    한글
    
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. alpha
    2. 한글
    Source evidence

    Return empty text at an empty input stream

    Link
    main.tpzReturn empty text at an empty input streamOpen in Playground
    1. import std.io
    2. let text = io.readStdin()
    3. let empty = text == ""
    4. io.writeLine("{empty}")
    Expected outputexit 0
    true
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. true
    Source evidence

    Observe EOF after standard input has been consumed

    Link
    main.tpzObserve EOF after standard input has been consumedOpen in Playground
    1. import std.io
    2. let first = io.readStdin()
    3. let second = io.readStdin()
    4. let atEnd = second == ""
    5. io.writeLine(first)
    6. io.writeLine("{atEnd}")
    Expected outputexit 0
    alpha
    true
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. alpha
    2. true
    Source evidence

    Menu

    Download