1
Fork 0
mirror of https://github.com/RGBCube/crash synced 2025-07-27 08:27:44 +00:00

Pass argv to processes

This commit is contained in:
RGBCube 2024-05-15 16:26:34 +03:00
parent e84f75f738
commit 00c77812f1
No known key found for this signature in database

View file

@ -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),