NSTask not picking up $PATH from the user’s environment

Try,

    [task setLaunchPath:@"/bin/bash"];
    NSArray *args = [NSArray arrayWithObjects:@"-l",
                     @"-c",
                     @"which git",
                     nil];
    [task setArguments: args];

This worked for me on Snow Leopard; I haven’t tested on any other system. The -l (lowercase L) tells bash to “act as if it had been invoked as a login shell”, and in the process it picked up my normal $PATH. This did not work for me if the launch path was set to /bit/sh, even with -l.

Leave a Comment