replaced fprintf, sprintf with dup2 and exec