@matheusbsbs / matheus-bagliano / commits / b73a439759
Fork 0

run-command: Support sending stderr to /dev/null

Some callers may wish to redirect stderr to /dev/null in some contexts, such as if they are executing a command only to get the exit status and don't want users to see whatever output it may produce as a side-effect of computing that exit status. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Nov 11, 2007 at 02:29 UTC b73a4397590df9582dd1c994cac30e55e26b0b1e
2 files changed +5 -2
run-command.c
+4 -2
@@ -41,7 +41,7 @@ int start_command(struct child_process *cmd)
41 cmd->close_out = 1;
42 }
43
44 - need_err = cmd->err < 0;
44 + need_err = !cmd->no_stderr && cmd->err < 0;
45 if (need_err) {
46 if (pipe(fderr) < 0) {
47 if (need_in)
@@ -87,7 +87,9 @@ int start_command(struct child_process *cmd)
87 close(cmd->out);
88 }
89
90 - if (need_err) {
90 + if (cmd->no_stderr)
91 + dup_devnull(2);
92 + else if (need_err) {
93 dup2(fderr[1], 2);
94 close_pair(fderr);
95 }
run-command.h
+1
@@ -23,6 +23,7 @@ struct child_process {
23 unsigned close_out:1;
24 unsigned no_stdin:1;
25 unsigned no_stdout:1;
26 + unsigned no_stderr:1;
27 unsigned git_cmd:1; /* if this is to be git sub-command */
28 unsigned stdout_to_stderr:1;
29 };