0

Possible Duplicate:
NSTask launch path not accessible

Any ideas why calling this,

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];

results in

'launch path not accessible' ?

thanks!

Community
  • 1
  • 1
trnc
  • 20,581
  • 21
  • 60
  • 98
  • Why are you escaping the space characters? it's supposed to be the path to a file, and thus the spaces aren't supposed to be escaped – Anya Shenanigans Oct 17 '12 at 16:25
  • It doesn't make any difference if the spaces are escaped or not... The same error occurs... – trnc Oct 17 '12 at 16:27
  • http://stackoverflow.com/questions/3221432/nstask-launch-path-not-accessible is about launching a shell script, so I do not think that it is a duplicate. – Martin R Oct 17 '12 at 17:20
  • Are you sure that you have removed `\\\` in both instances? Because it works on my computer. - Or are you building a sandboxed app? – Martin R Oct 17 '12 at 17:24

1 Answers1

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];

Works correctly, even logs that the executable exists. Remove the \\ in the executable name - all of them.

I'd recommend using the executable existence check before trying to run the app.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
  • If it isn't executable, how should we do then? Run chmod in run-time? – Itachi May 22 '13 at 15:13
  • NSTask takes an executable as the first option, if the item in question is not an executable then you should be asking *why*. if it's just that it's a script and it's not set as an executable, then follow the suggestion of the answer that this question is marked as a duplicate of. If it was in an app bundle and not marked as executable then you're building it incorrectly. – Anya Shenanigans May 22 '13 at 21:42