I am developing a macOS app using Objective-C that I want to run some commands same like terminal. Actually I want to run YOLO command from my application. I am using NSTask class for this. When I run the command through code, on task launch, I am getting error "Couldn't open file cfg/coco.data". The same command works fine with terminal but not in my application.
Here is my code:
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath:@"/bin/bash"];
NSString *commandToRun = @"Desktop/darknet/ && ./darknet detect cfg/yolo.cfg yolo.weights data/dog.jpg";
NSArray *arguments = [NSArray arrayWithObjects:
@"-c",
[NSString stringWithFormat:@"%@", commandToRun],
nil];
NSLog(@"run command: %@",commandToRun);
[task setArguments: arguments];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
NSData *data;
data = [file readDataToEndOfFile];
NSString *output;
output = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];