From 5730f148978541323e3c0b24de81bc37c127db90 Mon Sep 17 00:00:00 2001 From: utox39 Date: Mon, 25 Aug 2025 03:12:56 +0200 Subject: [PATCH] feat(linux-shell): use process.Child.run --- src/linux/user.zig | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/linux/user.zig b/src/linux/user.zig index 9f92373..8b63165 100644 --- a/src/linux/user.zig +++ b/src/linux/user.zig @@ -10,25 +10,18 @@ pub fn getShell(allocator: std.mem.Allocator) ![]u8 { return allocator.dupe(u8, "Unknown"); } else return err; - var child = std.process.Child.init(&[_][]const u8{ shell, "--version" }, allocator); defer allocator.free(shell); - child.stdout_behavior = .Pipe; - child.stderr_behavior = .Pipe; - - try child.spawn(); - - const output = try child.stdout.?.reader().readAllAlloc(allocator, 1024 * 1024); - - _ = try child.wait(); + const result = try std.process.Child.run(.{ .allocator = allocator, .argv = &[_][]const u8{ shell, "--version" } }); + const result_stdout = result.stdout; if (std.mem.indexOf(u8, shell, "bash") != null) { - const bash_version = parseBashVersion(output); - defer allocator.free(output); + const bash_version = parseBashVersion(result_stdout); + defer allocator.free(result_stdout); return try std.fmt.allocPrint(allocator, "{s} {s}", .{ "bash", bash_version.? }); } - return output; + return result_stdout; } fn parseBashVersion(shell_version_output: []u8) ?[]u8 {