Advertisement
Guest User

NSTask launch

a guest
Sep 25th, 2013
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     NSTask *task = [[NSTask alloc] init];
  2.     [task setLaunchPath: @"/usr/bin/grep"];
  3.     [task setArguments: @[ @"foo", @"bar.txt"]];
  4.  
  5.     NSPipe *pipe = [NSPipe pipe];
  6.     [task setStandardOutput: pipe];
  7.  
  8.     [task launch];
  9.  
  10.     NSFileHandle *file = [pipe fileHandleForReading];
  11.     NSString *string = [[NSString alloc] initWithData: [file readDataToEndOfFile]
  12.                                              encoding: NSUTF8StringEncoding];
  13.     NSLog (@"grep returned:\n%@", string);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement