How to get output from Admin Priveleges bash script called from Cocoa?

I use the code below to run the bash command with administrator privileges. I need to be able to store the output in an array after using it. How can I get the result?

 char *command1= "/usr/bin/dscl";

char *args1[] = {".","-read","/SharePoints/FolderName","directory_path",nil};

    FILE *pipe = nil;

                            err = AuthorizationCreate(nil,
                              kAuthorizationEmptyEnvironment,
                              kAuthorizationFlagDefaults,
                              &authorizationRef);

        err = AuthorizationExecuteWithPrivileges(authorizationRef,
                                               command,
                                              kAuthorizationFlagDefaults,
                                              args1,
                                              &pipe);    

The output should be a folder - The path of any shared folder. How can I get it and save in an array?

PS In NSTask can be done with NSPipe, but here is the file type.

Thank you so much!

0
source share
1 answer

Read from the POSIX ( FILE *) file descriptor returned to you AuthorizationExecuteWithPrivileges. Remember to close it when done.

+1
source

All Articles