@daniel Sure - I'd encapsulate the naked file descriptor in a RAII class that supports these operation on a higher level - but again, that's a completely new and different question. That type of question is more suited for
codereview - Two things though. You should always check for errors (both
open
and
dup2
may fail) and you could add
wait
or
waitpid
in the parent process to wait for the child to finish. —
Ted Lyngmo 17 secs ago