我想從我的objective-c項目運行終端命令。執行終端命令
當我從端子短運行它,我用:
cd /Users/user/Desktop/project/;ant release
現在我在Objective-C的項目中使用這樣的:
NSTask *task = [NSTask new];
[task setLaunchPath:@"cd /Users/user/Desktop/project/;ant"];
[task setArguments:[NSArray arrayWithObjects:@"release", nil]];
NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput:pipe];
[task launch];
NSData *data = [[pipe fileHandleForReading] readDataToEndOfFile];
[task waitUntilExit];
[task release];
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog (@"got\n%@", string);
[string release];
和[task launch];
後,我得到錯誤:
launch path not accessible
編輯
我試圖用這個命令檢查:
[task setCurrentDirectoryPath:@"/Users/user/Desktop/Czech/"];
[task setLaunchPath:@"/bin/ls"];
,它仍然給我一個警告:
working directory doesn't exist.
關於`工作目錄沒有按't exist`消息:檢查調用路徑到`setCurrentDirectoryPath:`,是否有拼寫錯誤? – sjs 2011-12-14 11:39:52