Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK turns out the answer is on stack overflow, but its spread across different questions.</p> <p>The question was asked here -> <a href="https://stackoverflow.com/questions/10965007/commands-with-nstask">Commands with NSTask</a> and here -> <a href="https://stackoverflow.com/questions/3221432/nstask-launch-path-not-accessible">NSTask launch path not accessible</a> as well </p> <p>But their answers as of this date arent clear as to what the problem was. It's only after reading the question from <a href="https://stackoverflow.com/questions/386783/nstask-not-picking-up-path-from-the-users-environment">NSTask not picking up $PATH from the user&#39;s environment</a> (the question's title was misleading) and with these two answers <a href="https://stackoverflow.com/questions/386783/nstask-not-picking-up-path-from-the-users-environment/1817870#1817870">NSTask not picking up $PATH from the user&#39;s environment</a> and <a href="https://stackoverflow.com/questions/208897/find-out-location-of-an-executable-file-in-cocoa/387809#387809">Find out location of an executable file in Cocoa</a> that I realized the solution.</p> <blockquote> <p>It looks like this is about setting up either NS Task or the user's shell (e.g., ~/.bashrc) so that the correct environment ($PATH) is seen by NSTask.</p> </blockquote> <p>Solution:</p> <pre><code>[task setLaunchPath:@"/bin/bash"]; NSArray *args = [NSArray arrayWithObjects:@"-l", @"-c", @"which git", //Assuming git is the launch path you want to run nil]; [task setArguments: args]; </code></pre> <p>However this assumes the user's shell is <strong>always</strong> bash and it will fail for others. Solve this by determining the shell.</p> <pre><code>NSDictionary *environmentDict = [[NSProcessInfo processInfo] environment]; NSString *shellString = [environmentDict objectForKey:@"SHELL"]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload