#Help with posix.exec types

1 messages · Page 1 of 1 (latest)

earnest agate
#

Hey everyone, I just finished going through ziglings and I'm trying to write some code, but I'm really struggling with getting the compiler happy.
I'm trying to call std.posix.execveZ and spawn a new zsh process. My issue is about what I need to pass to child_argv. I've tried several things like the following example, and different things that I don't have saved, but I just can't get the compiler to accept this, and surprisingly I haven't found any example online either.

const argv = [_:null]?[*:0]u8{"/usr/bin/zsh"};
_ = std.posix.execveZ(
    "/usr/bin/zsh",
    &argv,
    null,
);

execveZ has this definition: pub fn execveZ( path: [*:0]const u8, child_argv: [*:null]const ?[*:0]const u8, envp: [*:null]const ?[*:0]const u8, ) ExecveError, so what do I need to write for child_argv?

snow rampart
#

what is the error message

earnest agate
#

On the particular example it's

        const argv = [_:null]?[*:0]u8{"/usr/bin/zsh"};
                                      ^~~~~~~~~~~~~~
src/main.zig:41:39: note: a single pointer cannot cast into a many pointer
snow rampart
#

ah yeah

#

try @ptrCast on the string

earnest agate
#

Woo, I had to chain @constCast as well but that worked 😄

snow rampart
#

thonk really?

earnest agate
#

Surprised that it worked or surprised that I had to do the constCast?

snow rampart
#

oh change the type of your argv to [_:null]?[*:0]const u8

#

that's how it is in execveZ

#

that means it doesn't need to write into the strings, which you can't anyway since they are literals

earnest agate
#

Ah alright, got it

#

Now it's complaining about envp but I'll take a crack at it myself and see what happens