Question: What's the best way to directly pipe an NSTask's output to a file? I want to go through as few buffers in memory as possible.

Answer: 
Before launching the `NSTask` set the standard output and standard error (`setStandardOutput:`, `setStandardError:`) to an `NSFileHandle` for the output file (or files if you want a different one for each output).

An `NSFileHandle` is just a wrapper for the underlying OS file descriptor and the `NSTask` will do the appropriate work to connect that to the specified output (i.e. it will most likely do a dup(2)). No intermediate memory buffers should be introduced.

Once the `NSTask` is started you can (and should) close the `NSFileHandle` in your code.
I'll recap on CRD's correct answer, adding a code-snippet that demonstrates.

Here's a snippet that launches an `NSTask` to collect some logs (using the 'log show' command-line tool, redirecting the standard output to a file without allocating and maintaining buffers to do this.

```
NSString *logFilePath = [@"~/Desktop/MyLog.log" stringByStandardizingPath];
NSFileHandle *outFileHandle = [NSFileHandle fileHandleForWritingAtPath:logFilePath];
if(outFileHandle == nil) {
    [[NSFileManager defaultManager] createFileAtPath:logFilePath contents:nil attributes:nil];
    outFileHandle = [NSFileHandle fileHandleForWritingAtPath:logFilePath]; // create the file if needed
} else {
    [outFileHandle seekToEndOfFile]; // append to file if it already exists
}

NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/log"];
[task setArguments: @[@"show", @"--predicate", @"process == \"myProcessName\""]];
[task setStandardOutput: outFileHandle];

@try {
    [task launch];
    [outFileHandle closeFile];  // task already holds it, we need not.
    [task waitUntilExit];
    int status = [task terminationStatus];
    switch (status) {
        case EXIT_SUCCESS: {
            if ([[NSFileManager defaultManager] fileExistsAtPath:logFilePath] == NO)  {
                NSLog(@"Log file not created for some reason, but task succeeded.");
            }
            break;
        }
        case EXIT_FAILURE:
        default:
            NSLog(@"Failed to extract logs. Error:%d", status);
            break;
    }
} @catch (NSException *exception) {
    NSLog(@"Exception occurred running task: %@", exception);
}

```