Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Jun 2006 14:14:50 -0400 (EDT)
From:      Dan Ponte <dcp1990@neptune.atopia.net>
To:        FreeBSD-gnats-submit@FreeBSD.org
Cc:        dan@theamigan.net
Subject:   bin/99585: [PATCH] Add option to tee(1) to also copy to standard error
Message-ID:  <200606281814.k5SIEouW033968@fez.theamigan.net>
Resent-Message-ID: <200606281820.k5SIKOWS093452@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         99585
>Category:       bin
>Synopsis:       [PATCH] Add option to tee(1) to also copy to standard error
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jun 28 18:20:23 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Dan Ponte
>Release:        FreeBSD 6.1-STABLE amd64
>Organization:
Unix Users Anonymous
>Environment:
System: FreeBSD fez.theamigan.net 6.1-STABLE FreeBSD 6.1-STABLE #13: Sun Jun 25 23:43:46 EDT 2006 root@fez.theamigan.net:/usr/obj/usr/src/sys/FEZ amd64


>Description:
	I recently found myself in a situation where having tee(1) copy to standard error and standard output at the same time would be useful, so I implemented it.
>How-To-Repeat:
	Find yourself in said situation.
>Fix:
	Diff below.

--- tee.diff begins here ---
diff -ur tee.old/tee.1 tee/tee.1
--- tee.old/tee.1	Wed Jun 28 14:11:16 2006
+++ tee/tee.1	Wed Jun 28 14:07:37 2006
@@ -43,7 +43,7 @@
 .Nd pipe fitting
 .Sh SYNOPSIS
 .Nm
-.Op Fl ai
+.Op Fl ais
 .Op Ar
 .Sh DESCRIPTION
 The
@@ -61,6 +61,8 @@
 Ignore the
 .Dv SIGINT
 signal.
+.It Fl s
+Copy to standard error as well.
 .El
 .Pp
 The following operands are available:
diff -ur tee.old/tee.c tee/tee.c
--- tee.old/tee.c	Wed Jun 28 14:11:16 2006
+++ tee/tee.c	Wed Jun 28 14:06:37 2006
@@ -71,12 +71,14 @@
 	LIST *p;
 	int n, fd, rval, wval;
 	char *bp;
-	int append, ch, exitval;
+	int append, ch, exitval, sterrout;
 	char *buf;
 #define	BSIZE (8 * 1024)
 
 	append = 0;
-	while ((ch = getopt(argc, argv, "ai")) != -1)
+	sterrout = 0;
+
+	while ((ch = getopt(argc, argv, "ais")) != -1)
 		switch((char)ch) {
 		case 'a':
 			append = 1;
@@ -84,6 +86,9 @@
 		case 'i':
 			(void)signal(SIGINT, SIG_IGN);
 			break;
+		case 's':
+			sterrout = 1;
+			break;
 		case '?':
 		default:
 			usage();
@@ -96,6 +101,9 @@
 
 	add(STDOUT_FILENO, "stdout");
 
+	if (sterrout)
+		add(STDERR_FILENO, "stderr");
+
 	for (exitval = 0; *argv; ++argv)
 		if ((fd = open(*argv, append ? O_WRONLY|O_CREAT|O_APPEND :
 		    O_WRONLY|O_CREAT|O_TRUNC, DEFFILEMODE)) < 0) {
@@ -125,7 +133,7 @@
 static void
 usage(void)
 {
-	(void)fprintf(stderr, "usage: tee [-ai] [file ...]\n");
+	(void)fprintf(stderr, "usage: tee [-ais] [file ...]\n");
 	exit(1);
 }
 
--- tee.diff ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200606281814.k5SIEouW033968>