I am trying to write a simple Cocoa / Objective-C app which allows the user to specify a Folder and a search term, and then searches in all files in the folder for the search term. Essentially, I am trying to make a GUI interface for the "grep" UNIX command and it's results.
I am trying to use NSTask to create the shell command and return the results, but this is not working for whatever reason. I am able to get my search terms and directory strings just fine, but I get this message in my Run Log:
This is the NSTask setup:
Then I launch the task and try to read the results:
This command works fine in the terminal, so why doesn't NSTask return anything? I've been a programmer for a long time (C++, Java), but Objective-C and Cocoa are rather new to me. Thanks!
I am trying to use NSTask to create the shell command and return the results, but this is not working for whatever reason. I am able to get my search terms and directory strings just fine, but I get this message in my Run Log:
Code:
grep: /Users/oats/Desktop/wordpress_22/*: No such file or directory
This is the NSTask setup:
Code:
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/bin/grep"];
NSArray *arguments;
arguments = [NSArray arrayWithObjects: @"-l", @"-r", searchText, filepathstr, nil];
[task setArguments: arguments];
Then I launch the task and try to read the results:
Code:
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
NSData *data;
data = [file readDataToEndOfFile];
This command works fine in the terminal, so why doesn't NSTask return anything? I've been a programmer for a long time (C++, Java), but Objective-C and Cocoa are rather new to me. Thanks!