From 00c77812f131f0f0e6781c68e632f8551da0ac63 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Wed, 15 May 2024 16:26:34 +0300 Subject: [PATCH] Pass argv to processes --- src/main.zig | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main.zig b/src/main.zig index c958a89..f68efac 100644 --- a/src/main.zig +++ b/src/main.zig @@ -10,11 +10,22 @@ pub fn main() noreturn { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const alloc = gpa.allocator(); + var args = alloc.alloc([]const u8, std.os.argv.len) catch fallback(alloc); + defer alloc.free(args); + args.len = 0; + + var argi = std.process.args(); + while (argi.next()) |arg| { + args[args.len] = arg; + args.len += 1; + } + const shells = std.posix.getenv("SHELLS") orelse fallback(alloc); var it = std.mem.split(u8, shells, ":"); while (it.next()) |shell| { - var child = std.process.Child.init(&[_][]const u8{shell}, alloc); + args[0] = shell; + var child = std.process.Child.init(args, alloc); switch (child.spawnAndWait() catch fallback(alloc)) { std.process.Child.Term.Exited => |exit_code| if (exit_code == 0) std.process.exit(0),