public
Created

  • Download Gist
gistfile1.m
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
@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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.