One Quickie

Performing complex pipelines. (NSTask->General)
You can create multiple NSTasks and a bunch of NSPipes and hook them together, or you can use the "sh -c" trick to feed a shell a command, and let it parse it and set up all the IPC. This pipeline cats /usr/share/dict/words, finds all the words with 'ham' in them, reverses them, and shows you the last 5.
    NSTask *task;
    task = [[NSTask alloc] init];
    [task setLaunchPath: @"/bin/sh"];

    NSArray *arguments;
    arguments = [NSArray arrayWithObjects: @"-c",
                         @"cat /usr/share/dict/words | grep -i ham | rev | tail -5", nil];
    [task setArguments: arguments];
    // and then do all the other jazz for running an NSTask.
One important note:, don't feed in arbitrary user data using this trick, since they could sneak in extra commands you probably don't want to execute.

borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book