I'm trying to run a perl regex one liner on a bunch of files in a directory (via recursive find) and having a bit of trouble getting NSTask to do what the one line does on the command line.
The perl one liner in the terminal works, and a simplified NSTask running the command as a string through shell works too.
Perl command (works)
perl -p -i -e 's/DEBUG_INFORMATION_FORMAT = \"dwarf-with-dsym\";/DEBUG_INFORMATION_FORMAT = \"dwarf\";/g' `find . -name *.pbxproj`
Simple NSTask (works)
Using Inket's answer from another question:
NSString *command = @"perl -p -i -e 's/DEBUG_INFORMATION_FORMAT = \"dwarf-with-dsym\";/DEBUG_INFORMATION_FORMAT = \"dwarf\";/g' `find /Users/nflacco/Projects/XXX/XXX.xcodeproj -name *.pbxproj`";
NSTask* task = [[NSTask alloc] init];
[task setLaunchPath: @"/bin/sh"];
[task setArguments:@[@"-c", command]];
[task launch];
Xcode terminal app (doesn't work)
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSString *workspacePath = @"/Users/nflacco/Projects/XXX/XXX.xcodeproj";
NSString *old = @"DEBUG_INFORMATION_FORMAT = \"dwarf-with-dsym\";";
NSString *new = @"DEBUG_INFORMATION_FORMAT = \"dwarf\";";
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/perl"];
NSString *regex = [NSString stringWithFormat:@"'s/%@/%@/g'", old, new];
NSString *pathArg = [NSString stringWithFormat:@"`find %@ -name *.pbxproj`", workspacePath];
[task setArguments:@[ @"-p", @"-i", @"-e", regex, pathArg]];
[task launch];
}
return 0;
}
Xcode console:
Can't open `find /Users/nflacco/Projects/XXX/XXX.xcodeproj -name *.pbxproj`: No such file or directory.
Program ended with exit code: 0