{"thread":{"id":"12453","subject":"[PATCH] Redirect stderr to a pipe before redirecting stdout to stderr","startedAt":"2008-03-03T07:21:11Z","lastAt":"2008-03-03T08:07:35Z","messageCount":4,"participants":["Christian Couder","Shawn O. Pearce","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"70755","messageId":"20080303082111.24d3ea73.chriscool@tuxfamily.org","threadId":"12453","inReplyTo":null,"subject":"[PATCH] Redirect stderr to a pipe before redirecting stdout to stderr","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2008-03-03T07:21:11Z","receivedAt":"2008-03-03T07:21:11Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"With this patch, in the 'start_command' function after forking\nwe now take care of stderr in the child process before stdout.\n\nThis way if 'start_command' is called with a 'child_process'\nargument like this:\n\n\t.err = -1;\n\t.stdout_to_stderr = 1;\n\nthen stderr will be redirected to a pipe before stdout is\nredirected to stderr. So we can now get the process' stdout\nfrom the pipe (as well as its stderr).\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n run-command.c |   14 +++++++-------\n 1 files changed, 7 insertions(+), 7 deletions(-)\n\n\tThis patch should make my previous patch:\n\n\t[PATCH 1/2] help: add \"man.viewer\" config var to use \"woman\" or \"konqueror\"\n\n\twork as expected (at least with Emacs 21 and 22).\n\ndiff --git a/run-command.c b/run-command.c\nindex 743757c..44100a7 100644\n--- a/run-command.c\n+++ b/run-command.c\n@@ -91,6 +91,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@@ -103,13 +110,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"},{"id":"70758","messageId":"20080303073307.GG8410@spearce.org","threadId":"12453","inReplyTo":"20080303082111.24d3ea73.chriscool@tuxfamily.org","subject":"Re: [PATCH] Redirect stderr to a pipe before redirecting stdout to stderr","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-03-03T07:33:07Z","receivedAt":"2008-03-03T07:33:07Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> wrote:\n> With this patch, in the 'start_command' function after forking\n> we now take care of stderr in the child process before stdout.\n> \n> This way if 'start_command' is called with a 'child_process'\n> argument like this:\n> \n> \t.err = -1;\n> \t.stdout_to_stderr = 1;\n> \n> then stderr will be redirected to a pipe before stdout is\n> redirected to stderr. So we can now get the process' stdout\n> from the pipe (as well as its stderr).\n\nI'm in favor of this patch.  My series to add sideband support\nto send-pack/receive-pack (aka push) needed it for the hooks.\n\n-- \nShawn.\n"},{"id":"70760","messageId":"200803030852.43254.chriscool@tuxfamily.org","threadId":"12453","inReplyTo":"20080303073307.GG8410@spearce.org","subject":"Re: [PATCH] Redirect stderr to a pipe before redirecting stdout to stderr","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2008-03-03T07:52:42Z","receivedAt":"2008-03-03T07:52:42Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Le lundi 3 mars 2008, Shawn O. Pearce a écrit :\n> Christian Couder <chriscool@tuxfamily.org> wrote:\n> > With this patch, in the 'start_command' function after forking\n> > we now take care of stderr in the child process before stdout.\n> >\n> > This way if 'start_command' is called with a 'child_process'\n> > argument like this:\n> >\n> > \t.err = -1;\n> > \t.stdout_to_stderr = 1;\n> >\n> > then stderr will be redirected to a pipe before stdout is\n> > redirected to stderr. So we can now get the process' stdout\n> > from the pipe (as well as its stderr).\n>\n> I'm in favor of this patch.  My series to add sideband support\n> to send-pack/receive-pack (aka push) needed it for the hooks.\n\nNow that you say it, I remember having seen your patch, so please take \nownership of this patch.\n\nThanks,\nChristian.\n"},{"id":"70761","messageId":"47CBB1C7.8010201@viscovery.net","threadId":"12453","inReplyTo":"20080303082111.24d3ea73.chriscool@tuxfamily.org","subject":"Re: [PATCH] Redirect stderr to a pipe before redirecting stdout to stderr","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2008-03-03T08:07:35Z","receivedAt":"2008-03-03T08:07:35Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Christian Couder schrieb:\n> With this patch, in the 'start_command' function after forking\n> we now take care of stderr in the child process before stdout.\n> \n> This way if 'start_command' is called with a 'child_process'\n> argument like this:\n> \n> \t.err = -1;\n> \t.stdout_to_stderr = 1;\n> \n> then stderr will be redirected to a pipe before stdout is\n> redirected to stderr. So we can now get the process' stdout\n> from the pipe (as well as its stderr).\n\nMakes sense. All current users of .stdout_to_stderr don't modify the\nstderr channel, so this patch should not make a difference.\n\nBut please also adjust Documentation/technical/api-run-command.txt because\nit documents the behavior that you are modifying.\n\n-- Hannes\n"}]}