0

可能重复:
NSTask 启动路径不可访问

任何想法为什么要调用这个,

NSTask *buildMTask = [[NSTask alloc] init];
[buildMTask setLaunchPath:@"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\\ Simulator.app/Contents/MacOS/iPhone\\ Simulator"];
[buildMTask launch];

结果是

'启动路径不可访问' ?

谢谢!

4

1 回答 1

1
NSString *appname = @"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator";
NSTask *aTask = [[NSTask alloc] init];
[aTask setLaunchPath:appname];
BOOL exists = [[NSFileManager defaultManager] isExecutableFileAtPath:[aTask launchPath]];
NSLog(@"%@ '%@'\n", exists ? @"Exists" : @"Does Not Exist", [aTask launchPath]);
[aTask launch];

工作正常,甚至记录可执行文件存在。删除\\可执行文件名称中的 - 所有这些。

我建议在尝试运行应用程序之前使用可执行存在检查。

于 2012-10-17T17:26:20.273 回答