From ed5493f9825d7244bb489d160208bf708641d0b8 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Fri, 5 Dec 2025 03:49:44 -0300 Subject: codecrafters submit [skip ci] --- src/shell.zig | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/shell.zig') diff --git a/src/shell.zig b/src/shell.zig index c95d9d0..ac16cab 100644 --- a/src/shell.zig +++ b/src/shell.zig @@ -10,11 +10,18 @@ pub fn executeCommand( cmd_name: []const u8, args: ?[]const u8, output_redirect: ?[]const u8, + error_redirect: ?[]const u8, ) !builtins.CommandResult { if (std.mem.eql(u8, cmd_name, "exit")) return builtins.executeExit(); if (std.mem.eql(u8, cmd_name, "echo")) { - if (output_redirect) |file| { + if (error_redirect) |file| { + const fd = try std.fs.cwd().createFile(file, .{}); + fd.close(); + } + + if (output_redirect != null) { + const file = output_redirect.?; const fd = try std.fs.cwd().createFile(file, .{}); defer fd.close(); @@ -90,8 +97,8 @@ pub fn executeCommand( const argv = try parser.parseArgs(allocator, cmd_name, args); defer allocator.free(argv); - if (output_redirect) |file| { - try executor.runExternalProgramWithRedirect(allocator, program_path, argv, file); + if (output_redirect != null or error_redirect != null) { + try executor.runExternalProgramWithRedirect(allocator, program_path, argv, output_redirect, error_redirect); } else { try executor.runExternalProgram(allocator, program_path, argv); } -- cgit v1.2.3