From 9a135e52fccafabb494a05c19d9874dbf23c6f03 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Fri, 5 Dec 2025 04:07:36 -0300 Subject: codecrafters submit [skip ci] --- src/shell.zig | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/shell.zig') diff --git a/src/shell.zig b/src/shell.zig index 23e64d2..b15003e 100644 --- a/src/shell.zig +++ b/src/shell.zig @@ -12,6 +12,7 @@ pub fn executeCommand( output_redirect: ?[]const u8, error_redirect: ?[]const u8, append_output: ?[]const u8, + append_error: ?[]const u8, ) !builtins.CommandResult { if (std.mem.eql(u8, cmd_name, "exit")) return builtins.executeExit(); @@ -21,6 +22,17 @@ pub fn executeCommand( fd.close(); } + if (append_error) |file| { + _ = std.fs.cwd().openFile(file, .{ .mode = .write_only }) catch |err| { + if (err == error.FileNotFound) { + const new_fd = try std.fs.cwd().createFile(file, .{}); + new_fd.close(); + } else { + return err; + } + }; + } + if (output_redirect != null or append_output != null) { const file = if (output_redirect) |f| f else append_output.?; const is_append = append_output != null; @@ -111,8 +123,8 @@ pub fn executeCommand( const argv = try parser.parseArgs(allocator, cmd_name, args); defer allocator.free(argv); - if (output_redirect != null or error_redirect != null or append_output != null) { - try executor.runExternalProgramWithRedirect(allocator, program_path, argv, output_redirect, error_redirect, append_output); + if (output_redirect != null or error_redirect != null or append_output != null or append_error != null) { + try executor.runExternalProgramWithRedirect(allocator, program_path, argv, output_redirect, error_redirect, append_output, append_error); } else { try executor.runExternalProgram(allocator, program_path, argv); } -- cgit v1.2.3