```{index} single: dup2; POSIX function ``` ```{index} single: POSIX::dup2; Perl function ``` # dup2 Duplicate `$fd1` onto `$fd2`, closing `$fd2` first if necessary. ## Synopsis ```perl POSIX::dup2($fd, 1); # redirect stdout to $fd ``` ## What you get back The target fd on success, `undef` on failure. Either argument being negative is rejected with `$!` set to `EBADF`. ## Differences from upstream Fully compatible with upstream POSIX.