ast3r3x
2009-05-11, 23:00
So I'm playing with NSTask and trying to get it to work and I'm confused about what is happening. In processOutput it says [data length] is 0, although if I run "git diff" from the terminal in "/Users/dustins/Sites" then I get the output I'd expect. Shouldn't they be the same thing, what am I missing?
- (void)processOutput:(NSNotification *)aNotification {
NSFileHandle *readHandle = [aTask standardOutput];
NSData *data = [readHandle availableData];
NSLog(@"%d \n", [data length]);
[aTask release]; // Don't forget to clean up memory
aTask = nil; // Just in case...
}
- (IBAction)getDiff:(id)sender
{
aTask = [[NSTask alloc] init];
NSMutableArray *args = [NSMutableArray array];
NSPipe *pipe = [NSPipe pipe];
NSFileHandle *readHandle = [pipe fileHandleForReading];
/* set arguments */
[args addObject:@"diff"];
[aTask setLaunchPath:@"/usr/local/git/bin/git"];
[aTask setCurrentDirectoryPath:@"/Users/dustins/Sites"];
[aTask setArguments:args];
[aTask setStandardOutput:readHandle];
[aTask launch];
}
- (void)processOutput:(NSNotification *)aNotification {
NSFileHandle *readHandle = [aTask standardOutput];
NSData *data = [readHandle availableData];
NSLog(@"%d \n", [data length]);
[aTask release]; // Don't forget to clean up memory
aTask = nil; // Just in case...
}
- (IBAction)getDiff:(id)sender
{
aTask = [[NSTask alloc] init];
NSMutableArray *args = [NSMutableArray array];
NSPipe *pipe = [NSPipe pipe];
NSFileHandle *readHandle = [pipe fileHandleForReading];
/* set arguments */
[args addObject:@"diff"];
[aTask setLaunchPath:@"/usr/local/git/bin/git"];
[aTask setCurrentDirectoryPath:@"/Users/dustins/Sites"];
[aTask setArguments:args];
[aTask setStandardOutput:readHandle];
[aTask launch];
}