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:
parent
e84f75f738
commit
00c77812f1
1 changed files with 12 additions and 1 deletions
13
src/main.zig
13
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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue