spawnAndWait creates panic

Hello, I’m new to Zig and Ziggit.

I am building a toy project to open other programs (in my case I’m using Explorer to open the current directory the binary is in). When I run the binary/exe it seems to work perfectly fine, but there seems to be an error that pops up on the terminal. It seems to only be getting the error when it invokes the spawnAndWait() function from std.ChildProcess. I’m pretty lost right now, is there something I’m doing wrong?

// test_me.zig

const std = @import("std");
const process = std.process;
const ChildProcess = std.ChildProcess;

pub fn main() !void {
    const allocator = std.heap.page_allocator;

    var child_proc = ChildProcess.init(&.{ "explorer", "." }, allocator);

    var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
    const cwd = try process.getCwd(&buffer);

    child_proc.cwd = cwd;
    const proc_term = try child_proc.spawnAndWait();

    switch (proc_term) {
        .Exited => |code| {
            if (code != 0) {
                std.debug.print("Error!!! {d}\n", .{code});
                @panic("OH NOOOOO!!!\n");
            }
        },
        else => unreachable,
    }
}

I’m compiling it on my Ubuntu WSL by running:

zig build-exe -target x86_64-windows test_me.zig

And after running the exe, it successfully opens Explorer in the current directory, but the terminal gives this error:

Sorry if this was asked before, but I can only find questions that are similar to mine but not exactly a solution. Anyways, thanks for the help :slight_smile:

Hello @NEETdemon, welcome to ziggit :slight_smile:

It 's the windows explorer that returns 1 as exit code.
It is also reported as WSL issue.
If you don’t have a zig error, you can just ignore the exit code.

1 Like

Thank you so much! I didn’t know that’s how it worked on Windows.
Cheers! :partying_face:

1 Like