NSTask subclass problem

I cannot subclass NSTask with my class dcm2niiTask,

when I try to use the setLaunchPath in execution I have the following message:
* -setLaunchPath: only defined for abstract class. Define -[dcm2niiTask setLaunchPath:]!'

What is the reason?

Thank You a lot,

Fabrizio

Mac OS X (10.6.2)

Posted on Jan 13, 2010 7:45 AM

Reply
15 replies

Jan 13, 2010 10:12 AM in response to Volker Runkel

oh, you are right, I guessed there were some theoretical reason, and I shifted to has-a

this was my (is-a) code:

@interface dcm2niiTask : NSTask
...
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
dcm2niiTask *myTask;

myTask = [[dcm2niiTask alloc] init];
[myTask setLaunchPath: @"/bin/ls"];

NSArray *arguments;
arguments = [NSArray arrayWithObjects: @"-l", @"-a", @"-t", nil];
[myTask setArguments: arguments];

NSPipe *pipe;
pipe = [NSPipe pipe];
[myTask setStandardOutput: pipe];

NSFileHandle *file;
file = [pipe fileHandleForReading];

[myTask launch];

NSData *data;
data = [file readDataToEndOfFile];

NSString *string;
string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog (@"woop! got\n%@", string);

[myTask release];
[pool drain];
return 0;


All was right if I used
myTask = [[NSTask alloc] init];
instead of
myTask = [[dcm2niiTask alloc] init];

thanks,

Fabrizio

Jan 13, 2010 11:16 AM in response to Volker Runkel

thanks for the brackets,

yes I didn't write all the code,

there was the .h file with @interface dcm2niiTask : NSTask
members and methods,

there was the .m file with @implementation etc,

but the problem arises in the main program, basically when my object is declared as NSTask it is all right, when it is declared as dcm2niiTask (subclass of NSTask) in execution it is noticed that the method is abstract and that I have to declare it in my subclass...

fabrizio

Jan 13, 2010 11:37 AM in response to Dewey Sachs

I need to create a plugin for a medical image client/server software (Osirix) and I need to execute inside the plugin a shell script (dcm2nii, by Chris Rorden) that implements a conversion of medical format file (DICOM) in a research format one (Nifti).

I though to instruct a class (dcm2niiTask) to perform the conversion and to manage other staff concerning it. The main task of the class is to perform the conversion, i.e. to call the shell script.

that's all

fabrizio

Jan 13, 2010 12:25 PM in response to etresoft

HI,

This is my code, in three files (last one containing main)


//
// FF_dcm2niiTask.h
// FF_dcm2nii
//
// Created by Fabrizio Fasano on 1/13/10.
// Copyright 2010 _MyCompanyName_. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface FF_dcm2niiTask : NSTask
{
int aNumber;
}
-(void) chooseSource;
-(void) executeTask;
-(void) printaNumber;
@end
//
// FF_dcm2niiTask.m
// FF_dcm2nii
//
// Created by Fabrizio Fasano on 1/13/10.
// Copyright 2010 _MyCompanyName_. All rights reserved.
//
#import "FF_dcm2niiTask.h"
@implementation FF_dcm2niiTask
-(void) chooseSource
{
aNumber=1;
}
-(void) executeTask
{
aNumber=2;
}
-(void) printaNumber
{
NSLog(@"the aNumber value is: %i", aNumber);
}
@end
#import <Foundation/Foundation.h>
#import "FF_dcm2niiTask.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
FF_dcm2niiTask *myTask;
myTask = [FF_dcm2niiTask alloc];
[myTask init];
[myTask setLaunchPath: @"/bin/ls"];

NSArray *arguments;
arguments = [NSArray arrayWithObjects: @"-l", @"-a", @"-t", nil];
[myTask setArguments: arguments];

NSPipe *pipe;
pipe = [NSPipe pipe];
[myTask setStandardOutput: pipe];

NSFileHandle *file;
file = [pipe fileHandleForReading];

[myTask launch];

NSData *data;
data = [file readDataToEndOfFile];

NSString *string;
string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog (@"woop! got %@", string);

// work with class
[myTask chooseSource];
[myTask printaNumber];
[myTask executeTask];
[myTask printaNumber];

[myTask release];
[pool drain];
return 0;
}

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

NSTask subclass problem

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.