Jul 31, 2009 at 1:35pm
How can i use dup2 command to write the output of execl command to a file named "newfile.txt"??
# i am using sed command inside execl
Jul 31, 2009 at 4:34pm
Before you fork, create a new file descriptor via open() to newfile.txt.
After you fork and before you execl, in the child process, close stdin and stdout.
Then dup2( fd, 1 ); dup2( fd, 2 );
Then execl.
Now stdout and stderr of child process will be redirected to newfile.txt