0

I have a Mac (not iOS) application. I want to run a shell command 'find' after the user selects a folder with NSOpenPanel. The following is what I have.

NSString *path = [url path]; NSString *folderName = [path lastPathComponent]; NSTask *task = [[NSTask alloc] init]; [task setLaunchPath:@"/usr/bin/find"]; NSMutableString *command = [[NSMutableString alloc] initWithString:path]; [command appendString:@" -name '._*' -type f "]; NSArray* args = [NSArray arrayWithObjects:@"commit",command,nil]; [task setArguments:args]; NSPipe *pipe; pipe = [NSPipe pipe]; [task setStandardOutput: pipe]; [task launch]; NSFileHandle *file; file = [pipe fileHandleForReading]; NSData *data; data = [file readDataToEndOfFile]; NSString *output = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding]; NSLog(@"%@",output); 

It's my first time running a shell command with a Mac application that is developed with Objective-C. I suppose that I'm on the right track. Anyway, when I select a folder, I get the following debugger output message.

  • find: commit: No such file or directory
  • find: find: /Volumes/SDHC 16 GB/More -name '._*' -type f : No such file or directory

I suppose that the shell command cannot read this sort of file paths. Do I need to convert it into a shell path or whatever it understand? If so, how?

Thank you for your advice.

1 Answer 1

1

I got it.

NSString *path = [url path]; NSString *folderName = [path lastPathComponent]; NSTask *task = [[NSTask alloc] init]; [task setLaunchPath:@"/usr/bin/find"]; NSMutableString *command = [[NSMutableString alloc] initWithString:@""]; [command appendString:@" -name '._*' -type f"]; NSArray* args = [NSArray arrayWithObjects:path,command,nil]; [task setArguments:args]; NSPipe *pipe; pipe = [NSPipe pipe]; [task setStandardOutput: pipe]; [task launch]; NSFileHandle *file; file = [pipe fileHandleForReading]; NSData *data; data = [file readDataToEndOfFile]; NSString *output = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding]; NSLog(@"%@",output); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.