Alex Shnitman <[EMAIL PROTECTED]> writes:
> On Thu, 2002-09-12 at 16:03, [EMAIL PROTECTED] wrote:
>
> > i want to redirect both strdout and stderror into a pipe
> >
> > in tcsh i do: process1 |& process2
> > how do i do it in sh ? in bash ? ( is that the same )
>
> process1 2>&1 | process2
Note that this is not exactly what the OP asked for. What 2>&1 does
is duplicates stderr to stdout, and then redirects stdout *only* to
the pipe. See man bash for details.
I suspect that the proper answer is
process1 | 2>&1 process2
Subtle details can be shown using the trivial
#include <stdio.h>
int main(void)
{
fprintf(stdout,"stdout\n");
fflush(0);
fprintf(stderr,"stderr\n");
fflush(0);
return 0;
}
$ a.out 2>&1 | cat
stdout
stderr
$ a.out | 2>&1 cat
stderr
stdout
$ a.out 2>/dev/null 2>&1 | cat
stdout
stderr
$ a.out 2>/dev/null | 2>&1 cat
stdout
On the other hand, maybe "process1 2>&1 | process2" is exactly what
the OP wanted, it was not quite clear. I just thought one should be
aware of the difference.
--
Oleg Goldshmidt | [EMAIL PROTECTED]
=================================================================
"... Of theoretical physics and programming, programming embodied
the greater intellectual challenge." [E.W.Dijkstra, 1930 - 2002.]
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]