diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2025-08-13 19:21:03 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2025-08-13 19:21:03 +0200 |
commit | 621eaa97e417ce329c65ebf23d555ce34c39dddf (patch) | |
tree | c98088826725514873572057059291acf3a3704f /src | |
parent | 354dec925d6089133d1a0632ecdab4bd96d6c8ef (diff) |
Fix unredirected output combined with input redirection.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.zig | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/main.zig b/src/main.zig index ef537ea..3e2c266 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1087,6 +1087,15 @@ fn executeCommandWithOutput(command: Command, allocator: Allocator, output_captu }, .Redirect => |redirect| { + // Check if we have any output redirections + var has_output_redirect = false; + for (redirect.redirects.items) |redir| { + if (redir.redirect_type == .OutputOverwrite or redir.redirect_type == .OutputAppend) { + has_output_redirect = true; + break; + } + } + var captured_output = OutputCapture.init(allocator); defer captured_output.deinit(); @@ -1134,8 +1143,13 @@ fn executeCommandWithOutput(command: Command, allocator: Allocator, output_captu } } - // Execute the command with input and output capture - const status = try executeCommandWithOutput(redirect.command.*, allocator, &captured_output, if (redirect_input_source) |*source| source else null); + // Execute the command with input and output capture (only capture output if needed) + const status = try executeCommandWithOutput( + redirect.command.*, + allocator, + if (has_output_redirect) &captured_output else null, + if (redirect_input_source) |*source| source else null + ); // Handle output redirections for (redirect.redirects.items) |redir| { |