Skip to content

Instantly share code, notes, and snippets.

@vincent178
Created September 24, 2013 07:57
Show Gist options
  • Save vincent178/6681656 to your computer and use it in GitHub Desktop.
Save vincent178/6681656 to your computer and use it in GitHub Desktop.
Get NSTask Standard Output
NSTask * list = [[NSTask alloc] init];
[list setLaunchPath:@"/bin/ls"];
[list setCurrentDirectoryPath:@"/"];
NSPipe * out = [NSPipe pipe];
[list setStandardOutput:out];
[list launch];
[list waitUntilExit];
[list release];
NSFileHandle * read = [out fileHandleForReading];
NSData * dataRead = [read readDataToEndOfFile];
NSString * stringRead = [[[NSString alloc] initWithData:dataRead encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"output: %@", stringRead);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment