Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

File descriptors problem



Is it possible, to via some low level API, set up a file descriptor so that any data written to it,
will be echoed to 2 or more other file descriptors?
I want to redirect the output of NSLog, to my own logfile, while keeping all current destinations of log
messages.
The only way I've found so far is to call the following function:
int setup_logging()
{
int pipes[2];
int result = pipe(pipes);
int f = fork();
if (f) {
/* parent */
dup2(pipes[1],2);
close(pipes[1]);
close(pipes[0]);
return 0;
} else {
dup2(pipes[0],0);
close(pipes[0]);
close(pipes[1]);
execlp("/usr/bin/tee","tee","/Users/emac/Desktop/log",0);
fprintf(stdout,"failed\n");
exit(1);
}
}


Any help would be appreciated

-----------------------------------
See the amazing new SF reel: Invasion of the man eating cucumbers from outer space.
On congratulations for a fantastic parody, the producer replies : "What parody?"


Tommy Nordgren
email@hidden




_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.