Vitaly Fedrushkov wrote:

> > Date: Wed, 17 Feb 1999 12:00:18 +0000 (GMT)
> > From: Glynn Clements <[EMAIL PROTECTED]>
> > To: [EMAIL PROTECTED]
> > Subject: Re: stderr
> 
> > See the bash(1) manpage for more details of redirection. Also see the
> > dup2(2) manpage for details of the dup2() system call (which is used
> > to implement I/O redirection).
> 
> Another question came to mind: how do I redirect stderr _to_ stdout
> using dup2()?  The goal is: to have both output streams joined into
> one.

        dup2(STDOUT_FILENO, STDERR_FILENO);

This duplicates descriptor 1 (stdout) as descriptor 2 (stderr). 
Anything written to stderr then goes to the same place as for stdout.

If descriptor 2 previously referred to an open file (or whatever), it
will be closed by the call to dup2(). The state of whatever descriptor
1 referred to remains unchanged.

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to