Zig 0.16: new process.Child

This commit is contained in:
LN Liberda 2026-05-23 03:50:09 +02:00
parent 9b8e88c96d
commit 3ecdb536d3

View file

@ -665,24 +665,30 @@ pub fn runCmd(cmd: []const []const u8, cwd: ?[]const u8, reporterr: bool) void {
else
env.put("NCDU_LEVEL", "1") catch unreachable;
var child = std.process.Child.init(cmd, main.allocator);
child.cwd = cwd;
child.env_map = env;
var child = std.process.spawn(main.io, .{
.argv = cmd,
.cwd = if (cwd) |p| .{ .path = p } else .inherit,
.environ_map = &env,
}) catch |e| die("Failed to spawn process: {s}", .{errorString(e)});
const term = child.spawnAndWait() catch |e| blk: {
const term = child.wait(main.io) catch |e| blk: {
std.debug.print("Error running command: {s}\n\nPress enter to continue.\n", .{ ui.errorString(e) });
waitInput();
break :blk std.process.Child.Term{ .Exited = 0 };
break :blk std.process.Child.Term{ .exited = 0 };
};
const n = switch (term) {
.Exited => "error",
.Signal => "signal",
.Stopped => "stopped",
.Unknown => "unknown",
.exited => "error",
.signal => "signal",
.stopped => "stopped",
.unknown => "unknown",
};
const v = switch (term) { inline else => |v| v };
if (term != .Exited or (reporterr and v != 0)) {
const v: u32 = switch (term) {
.exited => |x| @intCast(x),
.signal, .stopped => |s| @intFromEnum(s),
.unknown => |x| x,
};
if (term != .exited or (reporterr and v != 0)) {
std.debug.print("\nCommand returned with {s} code {}.\nPress enter to continue.\n", .{ n, v });
waitInput();
}