# spawnAndWait creates panic

**URL:** <https://ziggit.dev/t/spawnandwait-creates-panic/4079>\
**Category:** Help\
**Tags:** compiler, standard-library\
**Created:** [April 24, 2024, 10:28pm UTC](https://ziggit.dev/t/spawnandwait-creates-panic/4079 "2024-04-24T22:28:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![NEETdemon](https://ziggit.dev/user_avatar/ziggit.dev/neetdemon/32/2236_2.png) [@NEETdemon](https://ziggit.dev/u/NEETdemon)\
**Post date:** [April 24, 2024, 10:28pm UTC](https://ziggit.dev/t/spawnandwait-creates-panic/4079/1 "2024-04-24T22:28:06Z")

</div>

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?

```zig
// 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:

```sh
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:

 ![Terminal](https://ziggit.dev/uploads/default/original/2X/e/ed9bb1546b49ce7047d6351e6a1c776302e4239a.png)

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 🙂

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [April 25, 2024, 12:32am UTC](https://ziggit.dev/t/spawnandwait-creates-panic/4079/2 "2024-04-25T00:32:09Z")

</div>

Hello @NEETdemon, welcome to ziggit 🙂

It 's the windows explorer that returns 1 as exit code.  
It is also reported as [WSL issue](https://github.com/microsoft/WSL/issues/6565).  
If you don’t have a zig error, you can just ignore the exit code.

---

<div class="post-metadata">

**Author:** ![NEETdemon](https://ziggit.dev/user_avatar/ziggit.dev/neetdemon/32/2236_2.png) [@NEETdemon](https://ziggit.dev/u/NEETdemon)\
**Post date:** [April 25, 2024, 2:50am UTC](https://ziggit.dev/t/spawnandwait-creates-panic/4079/3 "2024-04-25T02:50:33Z")

</div>

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