0
我需要一些NSTask的幫助。另外,我是Cocoa/Obj-C編程的新手,請耐心等待。我正在製作一個目錄。然後,將其刪除。所以這裏是我到目前爲止:可可NSTask幫助
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];
我的問題是,如果結束部分關於「釋放」 - 是正確的?如果沒有,有人可以幫我糾正它嗎?另外,如果我想做另一個「rmdir」的NSTask,我會只做「task = [[NSTask alloc] init];」等等我爲每個變量使用或將需要做出新的變量?非常感謝!
其實我只是以mkdir/rmdir爲例。我將爲其他命令執行此操作,例如dd,dns-sd,asr等。 – hassaanm 2010-07-07 17:27:05