Skip to content

allow user to write to standard input #23

Closed

Description

@ngphuctoan

I was trying out the playground with this snippet:

const std = @import("std");
const File = std.Io.File;

pub fn main(init: std.process.Init) !void {
    var stdin_buf: [1024]u8 = undefined;
    var stdout_buf: [1024]u8 = undefined;

    var stdin_reader = File.stdin().reader(init.io, &stdin_buf);
    const stdin = &stdin_reader.interface;

    var stdout_writer = File.stdout().writer(init.io, &stdout_buf);
    const stdout = &stdout_writer.interface;

    try stdout.writeAll("Enter your name: ");
    try stdout.flush();

    const name = try stdin.takeDelimiterExclusive('\n');
    stdin.toss(1);

    try stdout.print("Hello, {s}!\n", .{name});
    try stdout.flush();
}

Here is how it ran with a local Zig compiler:

> zig run hello.zig
Enter your name: Meep
Hello, Meep!

But in the playground, it exited with code 1:

Enter your name: �[31m�[1merror�[0m�[2m�[1m: �[0mEndOfStream


---
exit with exit code 1
---

Activity

  1. techatrix commented on Oct 26, 2026

    @techatrix
    Member

    There currently is no way to write to the program that can be read through stdin. The EndOfStream error is result of that.

    The unexpected control codes for color output will be fixed in the Zig 0.17.0 upgrade in #24. The output will then look like this:

    Enter your name: error: EndOfStream
    
    
    ---
    exit with exit code 1
    ---
    
  2. changed the title [-]EndOfStream exit code 1 with readers and writers[/-] [+]allow user to write to standard input[/+] on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions