#How to pass argv's when executing an external program?

1 messages · Page 1 of 1 (latest)

lost kite
#
const args = [_][*:null]const ?[*:0]const u8{"-xf", out_path};               
try std.os.execvpeZ("tar", args, .{out_path});

Or how to create a [*:null]const ?[*:0]const u8

I'm trying to execute tar using the standard library, but am not sure how to create a many-item pointer from values of known size. out_path is just a []u8.

#

How to pass argv's when executing an external program?

#

Hey @green siren, sorry to tag your from the either, but I figured you'd know.

green siren
#

Declare const args = [_:null]?[*:0]const u8{ "-xf", out_path.ptr };, and then pass args[0..], which will produce a *const [2:null]?[*:0]const u8, which ought to coerce implicitly to [*:null]const ?[*:0]const u8.
Of course, one glaring issue here is that out_path isn't null-terminated, so it can't be coerced to a null-terminated pointer as-is

#

If it already has a zero at the end, you can do out_path[0..:0].ptr - something to that effect. Otherwise you'll have to create a new string using something like Allocator.dupeZ

#

Though if you're using it in something like this, if possible, I'd suggest just starting off with a [:0]u8 to begin with