Redirect FROM stderr to another file descriptor Redirect FROM stderr to another file descriptor unix unix

Redirect FROM stderr to another file descriptor


You reversed the arguments: it's

dup2(from_fd, to_fd)

i.e.

dup2(fd, 2)

(see POSIX.2008 or your manpages.)


Just for completeness: You could even achieve your goal with freopen(name, mode, stderr), which is a Standard/ANSI/ISO C89 and C99 function.