{"thread":{"id":"10757","subject":"[PATCH 08/11] run-command: Support sending stderr to /dev/null","startedAt":"2007-11-09T11:06:35Z","lastAt":"2007-11-09T11:06:35Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":11},"messages":[{"id":"59026","messageId":"20071109110635.GH19368@spearce.org","threadId":"10757","inReplyTo":null,"subject":"[PATCH 08/11] run-command: Support sending stderr to /dev/null","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-11-09T11:06:35Z","receivedAt":"2007-11-09T11:06:35Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Some callers may wish to redirect stderr to /dev/null in some\ncontexts, such as if they are executing a command only to get\nthe exit status and don't want users to see whatever output it\nmay produce as a side-effect of computing that exit status.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n run-command.c |    6 ++++--\n run-command.h |    1 +\n 2 files changed, 5 insertions(+), 2 deletions(-)\n\ndiff --git a/run-command.c b/run-command.c\nindex d99a6c4..476d00c 100644\n--- a/run-command.c\n+++ b/run-command.c\n@@ -41,7 +41,7 @@ int start_command(struct child_process *cmd)\n \t\tcmd->close_out = 1;\n \t}\n \n-\tneed_err = cmd->err < 0;\n+\tneed_err = !cmd->no_stderr && cmd->err < 0;\n \tif (need_err) {\n \t\tif (pipe(fderr) < 0) {\n \t\t\tif (need_in)\n@@ -87,7 +87,9 @@ int start_command(struct child_process *cmd)\n \t\t\tclose(cmd->out);\n \t\t}\n \n-\t\tif (need_err) {\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}\ndiff --git a/run-command.h b/run-command.h\nindex 94e1e9d..1fc781d 100644\n--- a/run-command.h\n+++ b/run-command.h\n@@ -23,6 +23,7 @@ struct child_process {\n \tunsigned close_out:1;\n \tunsigned no_stdin:1;\n \tunsigned no_stdout:1;\n+\tunsigned no_stderr:1;\n \tunsigned git_cmd:1; /* if this is to be git sub-command */\n \tunsigned stdout_to_stderr:1;\n };\n-- \n1.5.3.5.1622.g41d10\n"}]}