Good I fixed that problem. A new one has risen. The following code outputs to the file, however any subsequent commands dont output to the stdout. For instance if after running in my shell, ls -l > foobar.txt, I run ls, the output for ls never appears on the stdout. Any ideas?
// Duplicate the stdout file handle and store it in orig_stdout.
orig_stdout = dup(fileno(stdout));
// This text appears on-screen.
// Reopen stdout and redirect it to the file.
freopen(args, "w", stdout);
// This text appears in the file.
pid = fork();
pid = wait(&ret_status);
//format execlp input
strncat(args, "\0", 1);
if(execlp(args, args, NULL))
// Close the redirected stdout.
// Restore the original stdout and print to the screen again.
printf("I'm back writing to the original stdout.\n");