git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/7] Allow run_command stdout_to_stderr when stderr is a pipe

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jan 30, 2008, 06:22 UTC
Message-ID
<20080130062200.GB15838@spearce.org>

To allow receive-pack hooks to have their stdout and stderr streams redirected to the same pipe we need to setup the pipe on fd 2 before we dup fd 2 over to fd 1. This way we can use a single pipe to capture both stdout and stderr and redirect it to a sideband channel, or elsewhere.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 run-command.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/run-command.c b/run-command.c
index 476d00c..52f80be 100644
--- a/run-command.c
+++ b/run-command.c
@@ -75,6 +75,13 @@ int start_command(struct child_process *cmd)
 			close(cmd->in);
 		}
 
+		if (cmd->no_stderr)
+			dup_devnull(2);
+		else if (need_err) {
+			dup2(fderr[1], 2);
+			close_pair(fderr);
+		}
+
 		if (cmd->no_stdout)
 			dup_devnull(1);
 		else if (cmd->stdout_to_stderr)
@@ -87,13 +94,6 @@ int start_command(struct child_process *cmd)
 			close(cmd->out);
 		}
 
-		if (cmd->no_stderr)
-			dup_devnull(2);
-		else if (need_err) {
-			dup2(fderr[1], 2);
-			close_pair(fderr);
-		}
-
 		if (cmd->dir && chdir(cmd->dir))
 			die("exec %s: cd to %s failed (%s)", cmd->argv[0],
 			    cmd->dir, strerror(errno));
-- 
1.5.4.rc5.1126.g6ba14
Message 1 of 1 in “Allow run_command stdout_to_stderr when stderr is a pipe”
  1. 2/7 Allow run_command stdout_to_stderr when stderr is a pipeShawn O. Pearce, Jan 30, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.