Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (fork() == 0)
- {
- // child
- int fd = open(file, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
- dup2(fd, 1); // make stdout go to file
- dup2(fd, 2); // make stderr go to file - you may choose to not do this
- // or perhaps send stderr to another file
- close(fd); // fd no longer needed - the dup'ed handles are sufficient
- exec(...);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement