{"thread":{"id":"11793","subject":"[PATCH 2/7] Allow run_command stdout_to_stderr when stderr is a pipe","startedAt":"2008-01-30T06:22:00Z","lastAt":"2008-01-30T06:22:00Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":7},"messages":[{"id":"66889","messageId":"20080130062200.GB15838@spearce.org","threadId":"11793","inReplyTo":null,"subject":"[PATCH 2/7] Allow run_command stdout_to_stderr when stderr is a pipe","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-01-30T06:22:00Z","receivedAt":"2008-01-30T06:22:00Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"To allow receive-pack hooks to have their stdout and stderr streams\nredirected to the same pipe we need to setup the pipe on fd 2 before\nwe dup fd 2 over to fd 1.  This way we can use a single pipe to\ncapture both stdout and stderr and redirect it to a sideband channel,\nor elsewhere.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n run-command.c |   14 +++++++-------\n 1 files changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/run-command.c b/run-command.c\nindex 476d00c..52f80be 100644\n--- a/run-command.c\n+++ b/run-command.c\n@@ -75,6 +75,13 @@ int start_command(struct child_process *cmd)\n \t\t\tclose(cmd->in);\n \t\t}\n \n+\t\tif (cmd->no_stderr)\n+\t\t\tdup_devnull(2);\n+\t\telse if (need_err) {\n+\t\t\tdup2(fderr[1], 2);\n+\t\t\tclose_pair(fderr);\n+\t\t}\n+\n \t\tif (cmd->no_stdout)\n \t\t\tdup_devnull(1);\n \t\telse if (cmd->stdout_to_stderr)\n@@ -87,13 +94,6 @@ int start_command(struct child_process *cmd)\n \t\t\tclose(cmd->out);\n \t\t}\n \n-\t\tif (cmd->no_stderr)\n-\t\t\tdup_devnull(2);\n-\t\telse if (need_err) {\n-\t\t\tdup2(fderr[1], 2);\n-\t\t\tclose_pair(fderr);\n-\t\t}\n-\n \t\tif (cmd->dir && chdir(cmd->dir))\n \t\t\tdie(\"exec %s: cd to %s failed (%s)\", cmd->argv[0],\n \t\t\t    cmd->dir, strerror(errno));\n-- \n1.5.4.rc5.1126.g6ba14\n"}]}