Hi I have the following code:
- (IBAction)runTask:(id)sender {
NSTask *proc;
NSPipe *output;
NSData *data;
NSString *buffer;
proc = [[NSTask alloc] init];
output = [[NSPipe alloc] init];
[proc setLaunchPath:@"/bin/sh"];
[proc setArguments:[NSArray arrayWithObjects: @"-c", @"/usr/bin/otool -L /Applications/TextEdit.app/Contents/MacOS/TextEdit | /usr/bin/awk 'NR>1{print $1}' | /usr/bin/sed -e '/@executable_path/d' -e 's/(.*)$//' -e 's/\\/Versions.*$//'", nil]];
[proc launch];
data = [[output fileHandleForReading] readDataToEndOfFile];
buffer = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"got: %@", buffer);
// Release
[proc release];
[output release];
[buffer release];
[data release];
}
The codes purpose is kinda complicated, it uses otool to get a list of the shared libraries used by a binary then it uses sed and awk to filter it into a machine readable format. Just to test I've used the Mac OS X TextEdit.app's binary.
The issue is that the code runs and returns an output but then freezes the app. I went through it line by line and found this line to be the problem:
data = [[output fileHandleForReading] readDataToEndOfFile];
This line itself is logging the output to the console and then freezing the app. I checked this by deleting all other lines after that line, and it still logs the output and freezes. There is nothing in debugger and any suggestions on how to solve this problem would be greatly appreciated.