我想叫可可應用UNIX命令,但它不工作,我想叫可可應用UNIX命令,但它不工作,
命令:「LUA -v」
可可代碼:
NSArray *cmdArray = [cmd componentsSeparatedByString:@" "];
NSPipe *pipe = [NSPipe pipe];
NSFileHandle *file = pipe.fileHandleForReading;
NSTask *task = [[NSTask alloc] init];
[task setStandardOutput:pipe];
task.launchPath = cmdArray[0];
if(cmdArray.count > 1)
{
task.arguments = [cmdArray subarrayWithRange:NSMakeRange(1, cmdArray.count - 1)];
}
[task launch] ;
NSData *data = [file readDataToEndOfFile];
[file closeFile] ;
NSString *grepOutput = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
return grepOutput;
的數據始終是0字節