From dcp1990@fez.theamigan.net  Wed Jun 28 18:14:55 2006
Return-Path: <dcp1990@fez.theamigan.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 62B5716A403
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 28 Jun 2006 18:14:55 +0000 (UTC)
	(envelope-from dcp1990@fez.theamigan.net)
Received: from eastrmmtao03.cox.net (eastrmmtao03.cox.net [68.230.240.36])
	by mx1.FreeBSD.org (Postfix) with ESMTP id A9CED43E98
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 28 Jun 2006 18:14:53 +0000 (GMT)
	(envelope-from dcp1990@fez.theamigan.net)
Received: from styx.theamigan.net ([68.9.18.102]) by eastrmmtao03.cox.net
          (InterMail vM.6.01.06.01 201-2131-130-101-20060113) with ESMTP
          id <20060628181452.CHSN23863.eastrmmtao03.cox.net@styx.theamigan.net>;
          Wed, 28 Jun 2006 14:14:52 -0400
Received: from fez.theamigan.net (fez.danponte.net [10.10.10.2])
	by styx.theamigan.net (8.13.6/8.13.4) with ESMTP id k5SIEqwC016259;
	Wed, 28 Jun 2006 14:14:52 -0400 (EDT)
	(envelope-from dcp1990@fez.theamigan.net)
Received: from fez.theamigan.net (localhost.theamigan.net [127.0.0.1])
	by fez.theamigan.net (8.13.6/8.13.6) with ESMTP id k5SIEotV033969;
	Wed, 28 Jun 2006 14:14:50 -0400 (EDT)
	(envelope-from dcp1990@fez.theamigan.net)
Received: (from dcp1990@localhost)
	by fez.theamigan.net (8.13.6/8.13.6/Submit) id k5SIEouW033968;
	Wed, 28 Jun 2006 14:14:50 -0400 (EDT)
	(envelope-from dcp1990)
Message-Id: <200606281814.k5SIEouW033968@fez.theamigan.net>
Date: Wed, 28 Jun 2006 14:14:50 -0400 (EDT)
From: Dan Ponte <dcp1990@neptune.atopia.net>
Reply-To: Dan Ponte <dcp1990@neptune.atopia.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc: dan@theamigan.net
Subject: [PATCH] Add option to tee(1) to also copy to standard error
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>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:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jun 28 18:20:23 GMT 2006
>Closed-Date:    Thu Jun 29 17:38:07 GMT 2006
>Last-Modified:  Thu Jun 29 17:38:07 GMT 2006
>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:

From: Bruce Evans <bde@zeta.org.au>
To: Dan Ponte <dcp1990@neptune.atopia.net>
Cc: FreeBSD-gnats-submit@freebsd.org, dan@theamigan.net,
        freebsd-bugs@freebsd.org
Subject: Re: bin/99585: [PATCH] Add option to tee(1) to also copy to standard
 error
Date: Thu, 29 Jun 2006 22:35:57 +1000 (EST)

 On Wed, 28 Jun 2006, Dan Ponte wrote:
 
 >> 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.
 
 Why not use a standard utility (tee itself in this case)?
 
    genoutput | tee /dev/stderr | tee foo
 
 copies the stdout of `genoutput' to stderr and to file foo.  This can be
 generalized to any number of copies on any numbers of file descriptors
 or files.
 
 The main problem with the utility method is is that the plumbing is
 very confusing even for only one extra pipeline stage.  /dev/stderr
 in the above refers to the initial stderr so it isn't affected by
 redirection unless the pipeline stages are run in subshells.  Running
 some of the stages in subshells makes the plumbing even more confusing.
 
 Bruce

From: Dan Ponte <dcp1990@neptune.atopia.net>
To: Bruce Evans <bde@zeta.org.au>
Cc: FreeBSD-gnats-submit@freebsd.org, freebsd-bugs@freebsd.org
Subject: Re: bin/99585: [PATCH] Add option to tee(1) to also copy to standard error
Date: Thu, 29 Jun 2006 11:54:57 -0400

 On Thu, Jun 29, 2006 at 10:35:57PM +1000, Bruce Evans <bde@zeta.org.au> was witnessed plotting the following conspiracy:
 > On Wed, 28 Jun 2006, Dan Ponte wrote:
 > 
 > >>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.
 > 
 > Why not use a standard utility (tee itself in this case)?
 > 
 >   genoutput | tee /dev/stderr | tee foo
 > 
 > copies the stdout of `genoutput' to stderr and to file foo.  This can be
 > generalized to any number of copies on any numbers of file descriptors
 > or files.
 > 
 > The main problem with the utility method is is that the plumbing is
 > very confusing even for only one extra pipeline stage.  /dev/stderr
 > in the above refers to the initial stderr so it isn't affected by
 > redirection unless the pipeline stages are run in subshells.  Running
 > some of the stages in subshells makes the plumbing even more confusing.
 > 
 > Bruce
 > 
 Hrm...this is a good idea. I never thought about that.
 -Dan
 -- 
 Dan Ponte
 http://www.theamigan.net/ -- ICQ: 175527699
 Jabber: dan@styx.theamigan.net -- AIM: amiganWS/amigan940
 To get something done, a committee should consist of no more than three
 persons, two of them absent.

From: Thomas David Rivers <rivers@dignus.com>
To: bde@zeta.org.au, dcp1990@neptune.atopia.net
Cc: freebsd-bugs@freebsd.org, FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/99585: [PATCH] Add option to tee(1) to also copy to standard error
Date: Thu, 29 Jun 2006 12:13:10 -0400 (EDT)

 > 
 > >>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.
 > 
 > Why not use a standard utility (tee itself in this case)?
 > 
 >   genoutput | tee /dev/stderr | tee foo
 > 
 > copies the stdout of `genoutput' to stderr and to file foo.  This can be
 > generalized to any number of copies on any numbers of file descriptors
 > or files.
 > 
 
 Uhh...
 
 What's wrong with:
 
 	genoutput 2>&1 | tee foo
 
 	- Dave Rivers -
 
 --
 rivers@dignus.com                        Work: (919) 676-0847
 Get your mainframe programming tools at http://www.dignus.com
 
 
State-Changed-From-To: open->closed 
State-Changed-By: linimon 
State-Changed-When: Thu Jun 29 17:37:19 UTC 2006 
State-Changed-Why:  
There are alternative approaches available with the existing tools.  But 
thanks for the submission. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=99585 
>Unformatted:
