Hey guys,
I need a bit of help with NSTask. Also, I am new to Cocoa / Obj-C programming, so please bear with me. I am trying to make a directory. Then, remove it. So here is what I have so far:
NSLog (@"START");
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath: @"/bin/mkdir"];
NSArray *arguments;
arguments = [NSArray arrayWithObjects: @"/tmp/TEMP", nil];
[task setArguments: arguments];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
[task setStandardError: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
NSLog (@"MKDIR");
[task launch];
[task waitUntilExit];
NSData *data;
data = [file readDataToEndOfFile];
string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog (@"OUTPUT:\n%@", string);
[task release];
//EDIT: The following lines should be removed and [string release]; should be added.
[arguments release];
[pipe release];
[file release];
[data release];
My question is if the part towards the end about "release"-ing is correct? If not, can someone help me correct it? Also, if I wanted to do another NSTask of "rmdir", would I just do "task = [[NSTask alloc] init];" and so on for each variable I used or will I need to make new variables? THANKS A LOT!