Hi everyone, after Catalina upgrade this simple grep call from a Mac app started to fail, while running it from Xcode I'm getting this error in the Xcode console: "
.../file.txt: Operation not permitted"
.It's kind of obvious that this is because of the security changes in Catalina, I've been looking for a while, but haven't been able to make it work, any idea on how to solve it?
Thanks in advance, this is the code I'm using:
- (void)simpleGrep{
NSPipe *pipe = [NSPipe pipe];
NSFileHandle *file = pipe.fileHandleForReading;
NSTask *task = [[NSTask alloc] init];
task.launchPath = @"/usr/bin/grep";
task.arguments = @[@"word", @"/Users/xxxxxxx/Documents/SampleFiles/file.txt"];
task.standardOutput = pipe;
[task launch];
NSData *data = [file readDataToEndOfFile];
[file closeFile];
NSString *output = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog (@"Finish with output: %@", output);
}
The NSLog prints "Finish with output: (null)".