0

From the Terminal, I can call all of the Salesforce DX CLI commands and functions. For example, "sfdx force:doc:commands:list" will show all the commands. BUT from the NSTask code (below) on a mac, I cannot call the Salesforce DX CLI at all. The terminationStatus flag is true. Other commands like "ls" work fine. Is this because of paths? permissions? Thanks in advance...

ptr portcommandlineinterface(char *thecommand)
{
    ptr theptr;
    NSTask *task;
    NSPipe *pipe;
    NSData *data;
    NSFileHandle *file;
    NSArray *arguments;
    int thesize, status;
    const char *junkptr;
    NSString *string, *tempstring;

    tempstring = [NSString stringWithUTF8String:thecommand];
    if (tempstring == 0) return(0);
    task = [[NSTask alloc] init];
    [task setLaunchPath: @"/bin/sh"];
    [task setCurrentDirectoryPath: @"~"];
    arguments = [NSArray arrayWithObjects: @"-c", tempstring, nil];
    [task setArguments: arguments];
    pipe = [NSPipe pipe];
    [task setStandardOutput: pipe];
    file = [pipe fileHandleForReading];
    [task launch];
    [task waitUntilExit];
    status = [task terminationStatus];
    if (status) return(0);
    data = [file readDataToEndOfFile];
    string = [[NSString alloc] initWithData: data encoding:NSUTF8StringEncoding];
    junkptr = [string UTF8String];
    thesize = cstrlen((char *)junkptr);
    theptr = portnewptr(thesize + 10);
    cstrcpy((char *)junkptr, theptr);
    return(theptr);
}
  • Looking at ENV, from NSTask we see: PATH=/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin And from Terminal we see: PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin So SFDX is installed in /usr/local/lib/ What is the right way to address this issue? Do I set the environment for nSTask? – Bill Appleton Jan 31 '18 at 21:41
  • Maybe I have solved this. Adding a @"-l" before the @"-c" makes bash run with the right path and sfdx works. But I would still like some insights here is there are any. – Bill Appleton Jan 31 '18 at 22:08

0 Answers0