Skip to content

zig run: Empty string arguments aren't forwarded on Windows #19236

Description

@castholm

Zig Version

0.12.0-dev.3161+377ecc6af

Steps to Reproduce and Observed Behavior

// repro.zig
const std = @import("std");
pub fn main() !void {
    var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator);
    defer arena_state.deinit();
    const arena = arena_state.allocator();
    const args = try std.process.argsAlloc(arena);
    for (args, 0..) |arg, i| std.debug.print("args[{}]: \"{s}\"\n", .{ i, arg });
}
zig run .\repro.zig -- hello "" world
args[0]: "C:\...\repro.exe"
args[1]: "hello"
args[2]: "world"

Running the executable directly works.

C:\...\repro.exe hello "" world
args[0]: "C:\...\repro.exe"
args[1]: "hello"
args[2]: ""
args[3]: "world"

Invoking the executable directly from Zig using std.process.Child.init(&.{ repro_path, "hello", "", "world" }, arena) also works, so it doesn't appear to be a bug in the argv-to-command line serialization logic.

Appears to be a Windows-only bug, people on Discord helped me verify that it works correctly on Linux and macOS.

zig build run (where run is a Step.Run) is also affected.

Expected Behavior

The empty string is passed to the spawned process.

Activity

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

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions