_dup2

Duplicates a file handle to another file handle.

int _dup2 (int handle1, int handle2);

int dup2 (int handle1, int handle2);

Required Header
<io.h>

Return Value

Each of these functions returns 0 on success. -1 indicates an error.

Parameters

handle1

  A handle to an open file

handle2

  Any handle value

Remarks

The _dup2 function creates a new handle to the currently open file handle handle1 and assigns it to handle handle2. Both the new handle and the old handle refer to the same file. If handle2 referes to a currently open file, it is closed first. Use _fileno to obtain the handle of a stream.

_dup2 is mostly used to assign an open file to the predefined handles for stdin, stdout and stderr .

Low Level I/O

See Also    _close, _dup, _open