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

[PATCH v2 1/6] run-command: Allow stderr to be a caller supplied pipe

From
Shawn O. Pearce <spearce@spearce.org>
Date
Feb 5, 2010, 20:57 UTC
Message-ID
<1265403462-20572-2-git-send-email-spearce@spearce.org>
In-Reply-To
<1265403462-20572-1-git-send-email-spearce@spearce.org>

Like .out, .err may now be set to a file descriptor > 0, which is a writable pipe/socket/file that the child's stderr will be redirected into.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 Documentation/technical/api-run-command.txt |    2 +-
 run-command.c                               |    8 ++++++++
 run-command.h                               |    2 +-
 3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/Documentation/technical/api-run-command.txt b/Documentation/technical/api-run-command.txt
index b26c281..a1280dd 100644
--- a/Documentation/technical/api-run-command.txt
+++ b/Documentation/technical/api-run-command.txt
@@ -135,7 +135,7 @@ stderr as follows:
 
 	.in: The FD must be readable; it becomes child's stdin.
 	.out: The FD must be writable; it becomes child's stdout.
-	.err > 0 is not supported.
+	.err: The FD must be writable; it becomes child's stderr.
 
   The specified FD is closed by start_command(), even if it fails to
   run the sub-process!
diff --git a/run-command.c b/run-command.c
index cf2d8f7..bfd2312 100644
--- a/run-command.c
+++ b/run-command.c
@@ -94,6 +94,9 @@ fail_pipe:
 		else if (need_err) {
 			dup2(fderr[1], 2);
 			close_pair(fderr);
+		} else if (cmd->err > 1) {
+			dup2(cmd->err, 2);
+			close(cmd->err);
 		}
 
 		if (cmd->no_stdout)
@@ -156,6 +159,9 @@ fail_pipe:
 	} else if (need_err) {
 		s2 = dup(2);
 		dup2(fderr[1], 2);
+	} else if (cmd->err > 2) {
+		s2 = dup(2);
+		dup2(cmd->err, 2);
 	}
 
 	if (cmd->no_stdout) {
@@ -228,6 +234,8 @@ fail_pipe:
 
 	if (need_err)
 		close(fderr[1]);
+	else if (cmd->err)
+		close(cmd->err);
 
 	return 0;
 }
diff --git a/run-command.h b/run-command.h
index fb34209..a29171a 100644
--- a/run-command.h
+++ b/run-command.h
@@ -18,7 +18,7 @@ struct child_process {
 	 * - Specify > 0 to set a channel to a particular FD as follows:
 	 *     .in: a readable FD, becomes child's stdin
 	 *     .out: a writable FD, becomes child's stdout/stderr
-	 *     .err > 0 not supported
+	 *     .err: a writable FD, becomes child's stderr
 	 *   The specified FD is closed by start_command(), even in case
 	 *   of errors!
 	 */
-- 
1.7.0.rc1.199.g9253ab
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 2 of 14 in “receive-pack hooks over sideband”
  1. 0/6 receive-pack hooks over sidebandShawn O. Pearce, Feb 5, 2010
  2. 1/6 run-command: Allow stderr to be a caller supplied pipeShawn O. Pearce, Feb 5, 2010
  3. 2/6 run-command: support custom fd-set in asyncShawn O. Pearce, Feb 5, 2010
  4. 3/6 send-pack: demultiplex a sideband stream with status dataShawn O. Pearce, Feb 5, 2010
  5. 4/6 receive-pack: Refactor how capabilities are shown to the clientShawn O. Pearce, Feb 5, 2010
  6. 5/6 receive-pack: Wrap status reports inside side-band-64kShawn O. Pearce, Feb 5, 2010
  7. Junio C HamanoFeb 5, 2010
  8. Shawn O. PearceFeb 5, 2010
  9. Junio C HamanoFeb 5, 2010
  10. 6/6 receive-pack: Send hook output over side band #2Shawn O. Pearce, Feb 5, 2010
  11. Larry D'AnnaFeb 9, 2010
  12. Shawn O. PearceFeb 9, 2010
  13. Larry D'AnnaFeb 9, 2010
  14. Larry D'AnnaFeb 9, 2010

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.