Created
January 25, 2010 06:52
-
-
Save richcollins/285688 to your computer and use it in GitHub Desktop.
This file contains 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
@implementation NSTask (Extras) | |
- (NSTaskResult *)result | |
{ | |
NSPipe *stdoutPipe = [NSPipe pipe]; | |
[self setStandardOutput:pipe]; | |
NSFileHandle *stdoutFile = [stdoutPipe fileHandleForReading]; | |
NSPipe *stderrPipe = [NSPipe pipe]; | |
[self setStandardError:stderrPipe]; | |
NSFileHandle *stderrFile = [stderrPipe fileHandleForReading]; | |
[self launch]; | |
[self waitUntilExit]; | |
NSData *stdoutData; | |
stdoutData = [stdoutFile readDataToEndOfFile]; | |
NSData *stderrData; | |
stderrData = [stderrFile readDataToEndOfFile]; | |
NSTaskResult *result = [NSTaskResult instantiate]; | |
result.stdout = [[[NSString alloc] initWithData:stdoutData encoding:NSUTF8StringEncoding] autorelease]; | |
result.stderr = [[[NSString alloc] initWithData:stderrData encoding:NSUTF8StringEncoding] autorelease]; | |
result.exitStatus = [self terminationStatus]; | |
return result; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment