Reputation: 316
I am trying to use SRCROOT
path in my project like so:
// Create NSTask to interact with console
NSTask *task;
task = [[NSTask alloc] init];
// Set path to script
NSString *launch_path = @"$SRCROOT/Scripts/my_script.rb";
NSLog(launch_path);
[task setLaunchPath:launch_path];
I end up with (in log):
$SRCROOT/Scripts/my_script.rb
I want to end up to a path inside my project's directory like this:
/Application/Scripts/my_script.rb
Can anyone help me understand what I'm doing wrong? Thanks in advance.
Additionally, I've tried the following without success:
..
// Set path to script
NSString *launch_path = [NSString stringWithFormat:@"%@/Scripts/auto_checkin.rb", "$SRCROOT"];
NSLog(launch_path);
..
Upvotes: 0
Views: 2387
Reputation: 6952
$SRCROOT is meaningless for runtime environment.
If you want to access the document in bundle, make sure the my_script.rb is added in the "Copy Bundle Resources", then try this:
NSString * path = [[NSBundle mainBundle] bundlePath] ;
path = [path stringByAppendingPathComponent:@"my_script.rb"] ;
$SRCROOT is path to the project file(*.xcodeproj) that defines the target. link here
The bundle term here represent Application bundle, the application bundle stores everything that the application requires for successful operation. link here
Upvotes: 3