summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2025-08-13 19:21:03 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2025-08-13 19:21:03 +0200
commit621eaa97e417ce329c65ebf23d555ce34c39dddf (patch)
treec98088826725514873572057059291acf3a3704f
parent354dec925d6089133d1a0632ecdab4bd96d6c8ef (diff)
Fix unredirected output combined with input redirection.
-rw-r--r--src/main.zig18
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| {