Created
September 24, 2013 07:57
-
-
Save vincent178/6681656 to your computer and use it in GitHub Desktop.
Get NSTask Standard Output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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