Hello,
I'm writing a Foundation tool and I need to run a NSTask in a separate thread. I have it working but when the task completes the thread is still running. I tried issuing a [NSThread exit] but that did nothing.

What am I missing?

Thanks,
tom


This my main code

#import <Foundation/Foundation.h>
#import "Threader.h"
#import "RunTask.h"

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

        Threader *oo = [[Threader alloc] init]; //Second Thread
        RunTask *newRunTask = [[RunTask alloc] init]; // Thrid Thread

        // Start second thread
        [NSThread detachNewThreadSelector:@selector(entryPoint:) toTarget:oo
withObject:[NSArray arrayWithObjects:@"SecondThread",@"10",nil]];
        
[NSThread detachNewThreadSelector:@selector(runSysProfiler:) toTarget:newRunTask withObject:nil];
        
        for (;;) {
                NSLog(@"Main Thread is running...");
                sleep(5);
        }
        
        [pool drain];
    return 0;
}

@implementation RunTask

-(void) runSysProfiler:(id *)obj {
        
        NSAutoreleasePool *newpool = [[NSAutoreleasePool alloc] init];
        
        NSLog(@"System Profiler Started, going to delay 10 seconds");
        [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:10]];
        NSLog(@"Thread delay done.");
        
        NSTask *sysProfiler = [[NSTask alloc] init];
        [swUpdate setLaunchPath:@"/usr/sbin/system_profiler"];
[swUpdate setArguments:[NSArray arrayWithObjects:@"SPHardwareDataType",nil]];
        
        NSPipe *pipe;
        pipe = [NSPipe pipe];
        [swUpdate setStandardOutput: pipe];
        
        NSFileHandle *file;
        file = [pipe fileHandleForReading];
        
        [sysProfiler launch];
        
        NSData *data;
         data = [file readDataToEndOfFile];
        
        NSString *string;
string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

        NSLog (@"Hey, we got it...\n%@", string);
        [newpool release];
}

@end
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to