Re: C and objective C together
Re: C and objective C together
- Subject: Re: C and objective C together
- From: Jonathan Wight <email@hidden>
- Date: Wed, 03 Apr 2002 11:59:42 -0600
On 04/03/2002 11:15, "Paul Ferguson" <email@hidden> wrote:
>
While the answers so far are interesting, I think they've missed the
>
essence of the question, which is:
>
>
How can I capture stdout and/or stderr output (whether from putc's,
>
printf's, NSLog's, NSAssert's, etc.) and redirect it to some object
>
inside my app, with little or no modifications to the app's code?
>
>
I don't know the answer, but am interested in this if someone does.
>
>
<fergy/>
Maybe this will help:
#import <Foundation/Foundation.h>
#include <unistd.h>
#include <fcntl.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
close(STDERR_FILENO);
int theNewSTDERR = open("test.txt", O_WRONLY | O_CREAT);
// insert code here...
NSLog(@"Hello, World!");
close(theNewSTDERR);
[pool release];
return 0;
}
Instead of using "open" just do whatever you want that creates a new file
descriptor. Also don't forget the same for stdout. (Oh and don't forget the
error checking)
Why do you want to do this though? Seems a little unusual to me.
Jon.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.