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.
Running a task via NSTask uses fork()
and exec()
to actually run the task. The user's interactive shell isn't involved at all. Since $PATH
is (by and large) a shell concept, it doesn't apply when you're talking about running processes in some other fashion.
Is /usr/local/git/bin in your $PATH when you run the program? I think which
only looks in the user's $PATH.